c#-5.0

Winforms asynchronous loading large data?

烂漫一生 提交于 2019-12-07 15:29:41
问题 I just received a bug list for an old app developed yeah years ago and one of the things i need to sort out is the amount of time it takes to load data into one screen,of course, while the screen is frozen and unfortunately this is in WinForms .NET 4.5. The data is loaded into a WinForms DataGridView. I would like to find out if there is any way of loading this data using C# 5 async and await,while refreshing the grid to add the next set of data. It may be while scrolling or in the background

Overload resolution, extension methods and genericity in C#

谁说胖子不能爱 提交于 2019-12-07 08:21:45
问题 I have the following scenario in my C# source: class A{} class Dispatch<T>{} static class DispatchExt { public static void D<T>(this Dispatch<T> d, int a) { Console.WriteLine("Generic D chosen with a = " + a.ToString()); } public static void D(this Dispatch<A> d, int a) { Console.WriteLine("D<A> chosen with a = " + a.ToString()); } } class Program { static void D<T>(Dispatch<T> d, int a) { d.D(a); } static void Main(string[] args) { int a = 5; var dispatch = new Dispatch<A>(); dispatch.D(a);

C#5 ReadAsync and Iterators

本小妞迷上赌 提交于 2019-12-07 08:17:01
问题 I am trying to convert the below class to lazily return a file. public class ObservableFile2 : IObservable<string> { private readonly IObservable<string> subject; public ObservableFile2(string fileName) { subject = Observable.Using<string, StreamReader> ( () => new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)), streamReader => ObserveLines(streamReader) ); } private IObservable<string> ObserveLines(StreamReader streamReader) { return ReadLines

Registering async factory in Autofac

情到浓时终转凉″ 提交于 2019-12-07 05:11:04
问题 I have a Wallet class that I get from a repository. I'm trying to properly register both in Autofac so classes using the wallet could have a proper instance injected. The problem is that the repository uses an async method (returning Task). Does Autofac support such cases? This doesn't work: cb.RegisterType<WalletRepository>() .As<IWalletRepository>() .SingleInstance(); cb.Register(async c => await c.Resolve<IWalletRepository>().CreateAsync(App.WalletPath)); cb.RegisterType<ViewModel>()

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

不羁岁月 提交于 2019-12-07 00:28:28
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.SqlClient;provider connection string="Data Source=192.168.0.89;Initial Catalog=WMSCMSWPROD;User ID=sa;Password

Read headers from HttpResponseMessage before Content is 100% complete

僤鯓⒐⒋嵵緔 提交于 2019-12-06 20:16:13
问题 How do I access the response headers, before the entire response has been streamed back? How do I read the stream as it arrives? Is HttpClient my best choice for such granular control of receiving the http response? Here's a snip that might illustrate my question: using (var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead)) { var streamTask = response.Content.ReadAsStreamAsync(); //how do I check if headers portion has completed? //Does

What is the best way to return completed Task?

痞子三分冷 提交于 2019-12-06 09:34:53
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? 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 s_completedTask = Task.FromResult(true); and then use s_completedTask. Task.FromResult would be the most

Invoking a Multi-Threaded DLL at Run-Time

不问归期 提交于 2019-12-06 05:35: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) { object result = null; result = methodInfo.Invoke(classInst, new object[] { dllParams }); return

Is there a way to Imitate C# 6 Null-Conditional operator in C# 5

亡梦爱人 提交于 2019-12-06 03:56:17
问题 I have a situation where I need to assign some objects' properties inside an object initializer. Some of these objects can be null and I need to access their properties, the problem is that they are too many, and using a if/else thing is not good. Example visits = visitJoins.AsEnumerable().Select(joined => new VisitPDV() { VisiteId = joined.Visite.VisiteId.ToString(), NomPointDeVente = joined.VisitePdvProduit.PointDeVente.NomPointDeVente, }); The joined.VisitePdvProduit can be null, and the

C#5 AsyncCtp BadImageFormatException

99封情书 提交于 2019-12-06 02:44:49
问题 Please help me with this one, I've been writing a console applicaiton using the AsyncCtpLibrary and the C#5 ctp compiler. First time I got to actually running a code which awaits, I got this: System.BadImageFormatException was unhandled Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) Source=AsyncCtpLibrary StackTrace: Server stack trace: at [...].<Execute>d__1c.MoveNext() at [...].Execute() at [...].<Move>d__1d.MoveNext() in[..]