begininvoke

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

最后都变了- 提交于 2019-12-22 04:53:05
问题 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

Invoke of an EventHandler

我的未来我决定 提交于 2019-12-21 11:32:51
问题 I have the following EventHandler: private EventHandler<MyEventArgs> _myEventHandler; public event EventHandler<MyEventArgs> MyEvent { add { _myEventHandler += value; } remove { _myEventHandler -= value; } } Could somebody explain the difference between the following snippets? Snippet EventHandler (A): //Snippet A: if (_myEventHandler != null) { _myEventHandler(new MyEventArgs()); } Snippet BeginInvoke (B): //Snippet B: if (_myEventHandler != null) { _myEventHandler.BeginInvoke(new

When is invoke required on GUI objects?

巧了我就是萌 提交于 2019-12-20 02:48:11
问题 Using C# Windows.Forms, do the methods Invalidate(), Refresh(), etc. have to be run on the main/GUI thread (require Invoke/BeginInvoke)? How about changes to members of a GUI object such as adding/deleting Points or changing the Color of a Series in a Charting.Chart object? I have some of these changes occuring in a worker thread without any issues (so I guess they are ok?), but I'm trying to distinguish which changes are explicity required on the GUI thread and which changes can occur on the

Windows Phone: how to tell when Deployment.Current.Dispatcher.BeginInvoke has completed?

こ雲淡風輕ζ 提交于 2019-12-19 03:59:36
问题 I'm trying to make the UI of a page in a WP7 application more responsive by putting the data loading portion into a background thread rather than running in the foreground when the page loads. The thread code essentially works through some data and adds items to an observable collection; in order to avoid exception issues, I execute something like: Deployment.Current.Dispatcher.BeginInvoke(() => { _events.Add(_newItem); }); so that the addition of the item to the collection is done in the UI

Update GUI from a non-GUI-Thread -> Not working with BeginInvoke()

六月ゝ 毕业季﹏ 提交于 2019-12-13 04:43:30
问题 I have created a simple WindowsForms-Application with one button and one label . If I click the button then the label should display the numbers from 1 to 100000. But if I click the button then the GUI freezes till the program counted to 100000 and then the label displays 100000 and the GUI stops freezing. The counting from 1 to 100000 is executed in a new thread (not the GUI thread) and then changing of the labeltext I try with BeginInvoke , but it don't works... using System.Drawing; using

c# wanting multiple ui threads but getting cross-reference errors instead

心已入冬 提交于 2019-12-12 04:58:00
问题 i'm still very new at c#, threads and forms. i'm writing a small data acquistion program. it has two threads: the main ui thread and a sensor polling/logging/charting thread. when the user clicks the "start-logging" button, it it continuously polls the sensors (over a virtual COM port), writes the response to a file, updates the main form with some basic polling stats (how many pollings per second). if the user has clicked a "monitor" button, it opens a charting form and the polling thread

Control.BeginInvoke Execution Order

浪尽此生 提交于 2019-12-11 20:05:40
问题 When calling BeginInvoke(), will the delegates comes back in the same order that the method is being called? or there is no guarantee which delegates will come back first? public Form1() { InitializeComponent(); for (int i = 0; i < 100; i++) { Thread t = new Thread(DisplayCount); t.Start(i); } } public void DisplayCount(object count) { if (InvokeRequired) { BeginInvoke(new Action<object>(DisplayCount), count); return; } listBox1.Items.Add(count); } And list of integers will come back out of

WinForm Control BeginInvoke/Invoke Issue

孤者浪人 提交于 2019-12-11 17:53:38
问题 I am trying to write a multithreaded WinForm in C++/CLI app using VS2012. I know that only the UI thread can update a control and I have been using delegates and the invoke methods. However, I have run into a memory access issue when using BeginInvoke that I do not see when using Invoke. Delegate Function: public: delegate void pictureboxShowDelegate(int tChannelNumber,System::Windows::Forms::PictureBox^,System::Drawing::Bitmap^ colorImage); Called Function: void DrawCVImageShow(int

Get input argument inside callback method

爷,独闯天下 提交于 2019-12-11 00:30:12
问题 In the code sample below , how to get input argument content inside callback method "MethodDone" ? I don't want to pass the input parameter again as the third argument of BeginInvoke , 'cause I want to call EndInvoke in callback method . static class Program { static void Main() { Action<string> del = new Action<string>(SomeMethod); del.BeginInvoke("input parameter", MethodDone, del); } static void MethodDone(IAsyncResult ar) { //how to get input parameter here ? Action<string> del = (Action

When is the GUI overloaded?

ぐ巨炮叔叔 提交于 2019-12-10 22:17:22
问题 Suppose you are permanently invoking a method asynchronously onto the UI thread/dispatcher with while (true) { uiDispatcher.BeginInvoke(new Action<int, T>(insert_), DispatcherPriority.Normal, new object[] { }); } On every run of the program you observe that the GUI of the application begins to freeze after about 90 seconds due to the flood of invocations (time varies but lies roughly between 1 and 2 minutes). How could one exactly determine (measure ?) the point when this overloading occurs