c#-5.0

What is [NotifyPropertyChangedInvocator] in C# when implements INotifyPropertyChanged?

时光毁灭记忆、已成空白 提交于 2019-12-09 07:28:27
问题 I see two types of implementation of INotifyPropertyChanged The first one: public abstract class ViewModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } } The second one: public abstract class ViewModelBase :

What is the best way to return completed Task?

偶尔善良 提交于 2019-12-09 03:58:28
问题 What is the best way to return a completed Task object? It is possible to write Task.Delay(0), or Task.FromResult<bool>(true) whatever. But what is the most efficient way? 回答1: Answer from Stephen Toub (MSFT): If you want a new Task object each time, Task.FromResult is the most efficient. Task.Delay(0) in its current implementation will return a cached task, but that's an implementation detail. If you want to use a cached task, you should cache one yourself, e.g. private static readonly Task

How to emulate C# 6 null-conditional in C# < 6

夙愿已清 提交于 2019-12-09 02:56:22
问题 With C# 6.0 I can do this var isEqual = x.Id == y.Id && x.UpdatedAt == y.UpdatedAt && x.Name == y.Name && x.RulesUrl == y.RulesUrl && x.OngoingChallenges?.Count == y.OngoingChallenges?.Count && x.MembershipIds?.Count == y.MembershipIds?.Count; Is there any nice solution to do this with C# < 6.0? I mean this part && x.OngoingChallenges?.Count == y.OngoingChallenges?.Count && x.MembershipIds?.Count == y.MembershipIds?.Count; Because in old projects we do not have possibility to use C# 6.0. How

Async method not returning immediately [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 19:09:28
This question already has an answer here : UI Thread blocked in C# WPF App during Async Download (1 answer) Closed 5 years ago . I am working from this solution: How to correctly write async method? However, the async method does not seem to return immediately, rather it takes a while. Here is the class Program { static void Main(string[] args) { Debug.WriteLine("Calling DoDownload"); var downloadTask = DoDownloadAsync(); Debug.WriteLine("DoDownload done"); downloadTask.Wait(); //Waits for the background task to complete before finishing. } private static async Task DoDownloadAsync() {

What are the risks of wrapping Async/Await IAsyncOperations with Task.Wait() code?

为君一笑 提交于 2019-12-08 17:22:48
问题 I'm currently trying to port a fair amount of existing synchronous code to WinRT. As part of this, I'm hitting problems with the existing code expecting some operations to be synchronous - e.g. for file I/O To adapt this existing code to work with the IAsyncOperation style API within WinRT, I've used a technique of wrapping the IAsyncOperation with an extension method like: namespace Cirrious.MvvmCross.Plugins.File.WinRT { public static class WinRTExtensionMethods { public static TResult

async await execution windows phone 8

无人久伴 提交于 2019-12-08 13:58:26
I am new to async and await style of programming. How can I solve the following problem: I am calling the below code first. The problem here is that the first line is awaiting which need to populate the categoriesvm.Categorieslist , which it does not, but the second line is called. (which I think is the default behaviour of await) How can I make sure that the second line is called only when the categoriesvm.Categorieslist is populated in the first line? protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { categoriesvm.GetCategories(); BookCategories

Async issue when changed method to use collection

橙三吉。 提交于 2019-12-08 12:45:44
问题 I had a method like that: public async Task<IEnumerable<Model>> Get(string link) { MyRequestAsync request = new MyRequestAsync(link); return await request.GetResult(); } It is working pretty well. Then I decided to change this one a little bit: public async Task<IEnumerable<Model>> Get([FromUri]IList<string> links) { IList<Model> list = new List<Model>(); foreach (var link in links) { MyRequestAsync request = new MyRequestAsync(link); list.Add(await request.GetResult()); } return list; } And

Reading from same SslStream simultaneously?

江枫思渺然 提交于 2019-12-08 12:22:59
问题 I am currently reading XML data from a SslStream. The stream is coming from a TcpClient object. using (XmlReader r = XmlReader.Create(sslStream, new XmlReaderSettings() { Async = true })) { while (await r.ReadAsync()) { ResetStream = false; switch (r.NodeType) { case XmlNodeType.XmlDeclaration: ... break; case XmlNodeType.Element: ... Additionally I would like to read every single bit and byte from the TcpClient directly regardless whether it is XML data or not. How can I read the same stream

Entity Connection String Constructor not found in EF 5 and WCF 4.5 at runtime

ぐ巨炮叔叔 提交于 2019-12-08 07:34:19
问题 I have developed web application using VS 2010, WCF 4.0 and EF 4.1.1. My WCF Service developed with multiple EF Connection strings configured in web.config file those are taken from Entity Model app.config file. based on the parameters i am redirecting databases with EF Connection string at runtime. My WCF4.0 web.config like: <connectionStrings> <add name="WMSChennaiDEVEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data

Invoking a Multi-Threaded DLL at Run-Time

我与影子孤独终老i 提交于 2019-12-07 19:37:32
问题 All, I call a .NET DLL containing a WinForm at run-time from a WinForm C# application. To do this I use the following: DLL = Assembly.LoadFrom(strDllPath); classType = DLL.GetType(String.Format("{0}.{1}", strNamespaceName, strClassName)); if (classType != null) { if (bDllIsWinForm) { classInst = Activator.CreateInstance(classType); Form dllWinForm = (Form)classInst; dllWinForm.Show(); // Invoke required method. MethodInfo methodInfo = classType.GetMethod(strMethodName); if (methodInfo != null