begininvoke

UI still non responsive after using control.begininvoke

女生的网名这么多〃 提交于 2019-12-06 12:20:13
i've made a C# winforms application. Now i have a form which has lots of buttons, which call huge number crunching functions whose output i update in a textbox. I call the textbox.begininvoke() method to which i pass a delegate to the function which updates the text in the textbox, however when the text is huge, the form is non responsive as i can't click on the cancel button. Isn't there any way so that the whole form remains responsive and as well the update too keeps happening. I have to show the data to the user as it is coming, i can't buffer the whole thing and show in the end. I also

When should I use UdpClient.BeginReceive? When should I use UdpClient.Receive on a background thread?

吃可爱长大的小学妹 提交于 2019-12-06 02:07:01
Essentially, what are the differences between these beyond the obvious? When should I use which form? class What { public Go() { Thread thread = new Thread(new ThreadStart(Go2)); thread.Background = true; thread.Start(); } private Go2() { using UdpClient client = new UdpClient(blabla) { while (stuff) { client.Receive(guh); DoStuff(guh); } } } } versus class Whut { UdpClient client; public Go() { client = new UdpClient(blabla); client.BeginReceive(guh, new AsyncCallback(Go2), null); } private Go2(IAsyncResult ar) { client.EndReceive(guh, ar); DoStuff(guh); if (stuff) client.BeginReceive(guh,

A threading problem where mono hangs and MS.Net doesn't

南笙酒味 提交于 2019-12-05 05:50:33
I'm testing my app with mono in prevision of a Linux port, and I have a threading problem. I initially considered pasting 3000 code lines here, but finally I've devised a small minimal example ;) You have a form with a button (poetically named Button1 , and a label (which bears, without surprise, the name Label1 )). The whole lot is living a happy life on a form called Form1 . Clicking Button1 launches an infinite loop that increments a local counter and updates Label1 (using Invoke ) to reflect its value. Now in Mono, if you resize the form, the label stops updating, never to restart. This

How to return T value from BeginInvoke?

别等时光非礼了梦想. 提交于 2019-12-04 20:34:48
I want to write a class to simplify the asynchronous programing, like string s = mylib.BeginInvoek(test,"1"); here is my code: public T BeginInvokeExWithReturnValue<T>(Func<T> actionFunction) { ExecWithReturnType<T> execWtihReturnValue = new ExecWithReturnType<T>(actionFunction); IAsyncResult iar = execWtihReturnValue.BeginInvoke(new AsyncCallback(EndInvokeExWithReturnValue<T>), execWtihReturnValue); // how to code here to return value } private void EndInvokeExWithReturnValue<T>(IAsyncResult iar) { ExecWithReturnType<T> execWtihReturnValue = (ExecWithReturnType<T>)iar.AsyncState;

Can I use BeginInvoke with a MulticastDelegate?

情到浓时终转凉″ 提交于 2019-12-03 17:17:48
问题 I want to raise a series of events from my library class, but I'm worried that some event subscribers will be rude and take a long time to process some events, thus blocking the thread that is raising the events. I thought I could protect the raising thread by using a thread pool thread to raise each event: if (packet != null && DataPacketReceived != null) { var args = new DataPacketEventArgs(packet); DataPacketReceived.BeginInvoke(this, args, null, null); } That works fine when there's only

Can I use BeginInvoke with a MulticastDelegate?

纵然是瞬间 提交于 2019-12-03 07:21:15
I want to raise a series of events from my library class, but I'm worried that some event subscribers will be rude and take a long time to process some events, thus blocking the thread that is raising the events. I thought I could protect the raising thread by using a thread pool thread to raise each event: if (packet != null && DataPacketReceived != null) { var args = new DataPacketEventArgs(packet); DataPacketReceived.BeginInvoke(this, args, null, null); } That works fine when there's only one subscriber to the event, but as soon as a second subscriber arrives, DataPacketReceived becomes a

How to Unit Test BeginInvoke on an Action

微笑、不失礼 提交于 2019-12-03 06:48:09
I am looking for a way to test BeginInvoke on an Action method, since the method runs on a background thread there is no way of knowing when it actually completes or calls callback method. I am looking for a way to keep my test wait until the callback gets called before making assertions. In the following Presenter class, you can notice that I am invoking PopulateView on background thread which updates the view when data is fetched and I am trying assert the view Properties are correctly initialized. I am using NUnit and Moq. public class Presenter { private IView _view; private IService

Invoke method for multi thread application?

最后都变了- 提交于 2019-12-02 20:19:16
问题 I have a bug in my application which is the same as here which this person was running into the same problem. My application is multi threaded where the worker thread is updating the Waveformgraph on the UI. I believe that is where my problem is and why, periodically, and on occassion I get a big red X in at least one of my waveformgraph objects when running the application. From reading and research, I need to use an Invoke or BeginInvoke method? Can someone please explain better and provide

Invoke method for multi thread application?

柔情痞子 提交于 2019-12-02 11:49:27
I have a bug in my application which is the same as here which this person was running into the same problem. My application is multi threaded where the worker thread is updating the Waveformgraph on the UI. I believe that is where my problem is and why, periodically, and on occassion I get a big red X in at least one of my waveformgraph objects when running the application. From reading and research, I need to use an Invoke or BeginInvoke method? Can someone please explain better and provide a sample code that is relevant to my code? The samples that I've found so far still have me hazy on

Confused by the behavior of Dispatcher.BeginInvoke()

こ雲淡風輕ζ 提交于 2019-12-01 14:30:34
问题 Could someone shed some light on an issue I'm having? I'm working on a wpf project. The scenario is as below: I need to pop up a window(model window) on main UI thread and then close it. These works are started from another UI thread (to deter user from clicking on the main UI window.) then I close this window. The main code are displayed below. And it works. As far as I know the close method would not get excuted before ShowDialog() returns (at least this is the case on UI thread, I mean