.net-4.0

Is this combination of ConcurrentDictionary and ConcurrentQueue thread-safe?

☆樱花仙子☆ 提交于 2019-12-23 07:32:06
问题 I'm using the ConcurrentDictionary and ConcurrentQueue classes from .NET 4 in the following code. Is this code thread-safe? If not, how can I make it thread-safe? public class Page { public string Name {get; set; } } public class PageQueue { private ConcurrentDictionary<int, ConcurrentQueue<Page>> pages = new ConcurrentDictionary<int, ConcurrentQueue<Page>>(); public void Add(int id, Page page) { if (!this.pages.ContainsKey(id)) this.pages[id] = new ConcurrentQueue<Page>(); this.pages[id]

How to add an item of type T to a List<T> without knowing what T is?

人走茶凉 提交于 2019-12-23 07:20:16
问题 I'm handling an event which passes event args pointing to a List and a T newitem, and my job is to add the newitem to the List. How can I do this without checking for all the types I know T might be? The current code is a couple dozen lines of this: private void DataGridCollectionViewSource_CommittingNewItem(object sender, DataGridCommittingNewItemEventArgs e) { Type t = e.CollectionView.SourceCollection.GetType(); if (t == typeof(List<Person>)) { List<Person> source = e.CollectionView

How to check a var for null value?

∥☆過路亽.° 提交于 2019-12-23 07:01:28
问题 I am using PetaPoco Micro-ORM with C# 4.0. The code below retrieves a single row from the database: var result = db.SingleOrDefault<TdUsers>(getUserQuery); I would like to check whether or not the result contains any rows, and whether is null. What is the best way to do this? 回答1: if (result == null || result.Count() == 0) { // Checks whether the entire result is null OR // contains no resulting records. } I think the problem is not in your check for null , because linq is lazy loading. Your

WCF, MySQL and Transaction

半城伤御伤魂 提交于 2019-12-23 06:28:25
问题 I am having a problem in MySql.Data.MySqlClient.MySqlTransaction in a Windows Communication Foundation Server Application. I am using the MySqlTransaction inside the method of the class that implements the ServiceContract Interface and it throws this error when I try to run the service: System.Runtime.Serialization.InvalidDataContractException : Type 'MySql.Data.MySqlClient.MySqlTransaction' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of

Windows Forms WebBrowser control error on .net 4.0 framework

只愿长相守 提交于 2019-12-23 05:38:06
问题 I have a fatal error thrown from my c# code where I have customized forms web browser to support browser autocomplete functionality. The exception gets thrown only on .net 4.0 framework, when we try to obtain the WebBrowserSite COM interfaces. error thrown at _baseIDocHostUiHandler = (WebBrowserNativeMethods.IDocHostUIHandler) Marshal.GetTypedObjectForIUnknown(_unkInnerAggregated, typeof (WebBrowserNativeMethods.IDocHostUIHandler)); Code: // constructor public AutoCompleteWebBrowserSite

ASP.NET MVC : Using the same database for Entity Framework and ASP.NET Membership

浪尽此生 提交于 2019-12-23 04:05:08
问题 Im trying to user ASP.NET MVC3 with Entity Framework and ASP.NET Membership for authentication. I've set up an existing database as my application services database for membership. When i create the entity data model through the wizard it adds the following connection string to my web.config. <add name="DBEntities" connectionString="metadata=res://*/Models.DB.csdl|res://*/Models.DB.ssdl|res://*/Models.DB.msl;provider=System.Data.SqlClient;provider connection string="Data Source=PM\SQLEXPRESS

Compare 2 XML files using just C#

倾然丶 夕夏残阳落幕 提交于 2019-12-23 04:04:45
问题 I'm looking for a way to compare to XML files (examples below) and create a list containing the xpath to the differences in the two files so I can then check what has changed. can this be done in Linq or will I need to use MS Diff patch, I would really like to do it all in C# without any additional Dlls. Or should I just loop trough one XML file and compare it to the other, but then if I do this I may miss any new or deleted nodes! File A <info> <Retrieve> <LastNameInfo> <LNameNum>1</LNameNum

Converting IEnumerable<T> to List<T> on a LINQ result, huge performance loss

∥☆過路亽.° 提交于 2019-12-23 03:21:39
问题 On a LINQ-result you like this: var result = from x in Items select x; List<T> list = result.ToList<T>(); However, the ToList<T> is Really Slow, does it make the list mutable and therefore the conversion is slow? In most cases I can manage to just have my IEnumerable or as Paralell.DistinctQuery but now I want to bind the items to a DataGridView, so therefore I need to as something else than IEnumerable , suggestions on how I will gain performance on ToList or any replacement? On 10 million

How can I run a WCF service constructor once for all clients when it's InstanceContextMode is set to PerSession?

*爱你&永不变心* 提交于 2019-12-23 03:17:30
问题 How can I run the code in the constructor of a WCF Service only once when the ServiceBehaviorAttribute.InstanceContextMode is set to PerSession ? [ServiceBehavior( InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)] public class SomeService : ISomeService { public SomeService() { this.RunThisOnceForAllClients(); } private void RunThisOnceForAllClients() { } } Or, how can I make a method run automatically once the WCF Service is running but it will

ASP.NET 4 changes with automatic names of controls

泄露秘密 提交于 2019-12-23 03:12:50
问题 I just updated an app from .NET 2.0 to .NET 4.0 and I have noticed the following. For example I have the following control: <input type="hidden" name="ctl00$cphMain$hfdFueraHorarioOficinaConfirmado" id="cphMain_hfdFueraHorarioOficinaConfirmado" value="False" /> and then in javascript I did this before: var hfdFueraHorarioOficinaConfirmado=document.getElementById('ctl00_cphMain_hfdFueraHorarioOficinaConfirmado'); but after checking the id within the html source once it renders and also doing