Questions tagged [begininvoke]

The Windows-specific Dispatcher.BeginInvoke API method

The Windows-specific Dispatcher.BeginInvoke API method.

This API call asynchronously runs a delegate on the dispatcher-associated thread.

280 questions
443
votes
6 answers

What's the difference between Invoke() and BeginInvoke()

Just wondering what the difference between BeginInvoke() and Invoke() are? Mainly what each one would be used for. EDIT: What is the difference between creating a threading object and calling invoke on that and just calling BeginInvoke() on a…
Nathan W
  • 54,475
  • 27
  • 99
  • 146
84
votes
5 answers

Dispatcher.BeginInvoke: Cannot convert lambda to System.Delegate

I'm trying to call System.Windows.Threading.Dispatcher.BeginInvoke. The signature of the method is this: BeginInvoke(Delegate method, params object[] args) I'm trying to pass it a Lambda instead of having to create a…
Micah
  • 111,873
  • 86
  • 233
  • 325
64
votes
2 answers

How to use BeginInvoke C#

Could you explain this for me please: someformobj.BeginInvoke((Action)(() => { someformobj.listBox1.SelectedIndex = 0; })); Could you tell me how can I use begininvoke exactly? What is Action type? Why there is blank brackets ()? And what does…
Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99
52
votes
7 answers

How to get return value when BeginInvoke/Invoke is called in C#

I've this little method which is supposed to be thread safe. Everything works till i want it to have return value instead of void. How do i get the return value when BeginInvoke is called? public static string readControlText(Control varControl)…
MadBoy
  • 10,824
  • 24
  • 95
  • 156
42
votes
1 answer

Dispatcher Invoke(...) vs BeginInvoke(...) confusion

I'm confused why I can't make this test counter application work with 2 (or more) simultaneous running countertextboxes with the use of "BeginInvoke" on my Dispatcher in the Count() method. You can solve the issue by replacing the BeginInvoke by an…
Jerev
  • 431
  • 1
  • 4
  • 6
35
votes
8 answers

System.Windows.Threading.Dispatcher and WinForms?

Does a System.Windows.Threading.Dispatcher work on the UI-thread of a WinForms application? If yes, why? It is coming from WindowsBase.dll which seems to be a WPF component. If not, how can I invoke work units back onto the UI-thread? I've found…
David Schmitt
  • 58,259
  • 26
  • 121
  • 165
26
votes
13 answers

Display progress bar while doing some work in C#?

I want to display a progress bar while doing some work, but that would hang the UI and the progress bar won't update. I have a WinForm ProgressForm with a ProgressBar that will continue indefinitely in a marquee fashion. using(ProgressForm p = new…
Priyank Bolia
  • 14,077
  • 14
  • 61
  • 82
26
votes
3 answers

Must every BeginInvoke be followed by an EndInvoke?

This page in the MS documentation, covering asynchrony in Windows Forms applications, states: You can call EndInvoke to retrieve the return value from the delegate, if neccesary, but this is not required. (emphasis added) This page covering the…
Cheeso
  • 189,189
  • 101
  • 473
  • 713
25
votes
7 answers

Is Delegate.EndInvoke() really necessary?

I've read a couple of forums and even a stackoverflow question or two saying that Delegate.EndInvoke is necessary when using Delegate.BeginInvoke. Many of the articles I've read talking about using BeginInvoke have failed to mention using…
Achilles
  • 11,165
  • 9
  • 62
  • 113
19
votes
5 answers

Invoke and BeginInvoke

Greetings, I am developing some application in C#. At the moment I'm dealing with threading and I have a question that I have in my mind. What is the difference between Invoke and BeginInvoke? I read some thread and I found some useful information…
niao
  • 4,972
  • 19
  • 66
  • 114
19
votes
6 answers

Anonymous method as parameter to BeginInvoke?

Why can't you pass an anonymous method as a parameter to the BeginInvoke method? I have the following code: private delegate void CfgMnMnuDlg(DIServer svr); private void ConfigureMainMenu(DIServer server,) { MenuStrip mnMnu =…
Charles Bretana
  • 143,358
  • 22
  • 150
  • 216
16
votes
2 answers

Two questions about AsyncCallback and IAsyncResult pattern

Two questions on the callback pattern with AsyncCallback and IAsyncResult. I changed the question with a code example: using System; using System.Collections.Generic; using System.Text; namespace TestAsync { class Program { private…
Gerard
  • 13,023
  • 14
  • 72
  • 125
16
votes
4 answers

Will multiple Control.BeginInvoke/Invoke calls execute in order?

I need to know whether Control.BeginInvoke and Control.Invoke calls will execute in the order they are called. I have the following scenario: UI thread is blocked WCF thread calls Control.BeginInvoke WCF thread calls Control.Invoke (or possibly…
cornergraf
  • 562
  • 8
  • 22
12
votes
2 answers

Confused by the behavior of Dispatcher.BeginInvoke()

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…
xiaoheixiaojie
  • 145
  • 1
  • 2
  • 8
11
votes
1 answer

Can I use BeginInvoke with a MulticastDelegate?

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…
Don Kirkby
  • 53,582
  • 27
  • 205
  • 286
1
2 3
18 19