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
7
votes
3 answers

Invoke() and BeginInvoke() behaving differently when executing an overridable method via a delegate

Can anyone tell me why this code behaves the way it does? See comments embedded in the code... Am I missing something really obvious here? using System; namespace ConsoleApplication3 { public class Program { static void Main(string[]…
6
votes
2 answers

beginInvoke, GUI and thread

I have application with two thread. One of them (T1) is main GUI form, another (T2) is function working in loop. When T2 gets some information must call function with GUI form. I'm not sure that I do it right. T2 call function FUNCTION, which…
nirmus
  • 4,913
  • 9
  • 31
  • 50
6
votes
1 answer

BeginInvoke with/without using MethodInvoker—does it make any difference?

I've seen these 2 versions of code while looking at some other developers' code: 1. Me.BeginInvoke(New MethodInvoker(Sub() cbo.ShowPopup())) 2. Me.BeginInvoke(Sub() cbo.ShowPopup() End Sub) Are both…
MJ Khan
  • 1,696
  • 3
  • 21
  • 36
6
votes
4 answers

Performance implications of BeginInvoke

I've inherited code where BeginInvoke is called from the main thread (not a background thread, which is usually the pattern). I am trying to understand what it actually does in this scenario. Does the method being called in the BeginInvoke get in…
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
6
votes
3 answers

How do I delegate an AsyncCallback method for Control.BeginInvoke? (.NET)

Is it possible to use Control.BeginInvoke in anything other than a "fire & forget" manner? I want to change the following request to delegate a callback method so that i can do something when each of my asynchronous calls…
Sheed
  • 113
  • 1
  • 9
6
votes
1 answer

BeginInvoke is blocking the UI, whereas Invoke is not. Why?

I am confused with scenario which I have encountered with cross thread access. Here is what I am trying to do: Main UI thread - menu item click I create a background worker and run it asynchronously private void actionSubMenuItem_Click(object…
Nagaraj Tantri
  • 5,172
  • 12
  • 54
  • 78
5
votes
2 answers

Better time-out detection for synchronous operations

I need a way to perform some action synchronously which should complete in half a second, but might just hang around for minutes. If it times out I don't care about the result. Here's the I'm doing it right now using compiler-generated…
repka
  • 2,909
  • 23
  • 26
5
votes
4 answers

Why doesn't this C# 4.0 async method get called?

I'm trying to write a really simple bit of async code. I have a void method that doesn't take any parameters, which is to be called from a Windows service. I want to kick it off async, so that the service doesn't have to hang around waiting for the…
Avrohom Yisroel
  • 8,555
  • 8
  • 50
  • 106
5
votes
2 answers

Execution order of asynchronously invoked methods

When I am invoking a number of methods to a Dispatcher, say the Dispatcher of the UI Thread, like here uiDispatcher.BeginInvoke(new Action(insert_), DispatcherPriority.Normal); uiDispatcher.BeginInvoke(new Action(add_),…
marc wellman
  • 5,808
  • 5
  • 32
  • 59
4
votes
2 answers

Why use Dispatcher.BeginInvoke?

I have seen (and read) about using Dispatcher.BeginInvoke to ensure that UI updates occur on the UI thread. I understand this reasoning. But I have seen examples where in the view code-behind, assigning properties, such as the Text property for a…
AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140
4
votes
1 answer

Wait until a delegate is called

I have an asynchronous class with a StartProcessing() method, that raises an int ResultReady() event when it has finished processing. StartProcessing() takes very little time. I want to call this class synchronously. My pseudo-code should be…
Ilya Kogan
  • 21,995
  • 15
  • 85
  • 141
4
votes
1 answer

Is there a variant of Control.BeginInvoke which works before/after the handle is destroyed?

I have a control which displays the state of an underlying asynchronous object. The object raises events, which arrive at the form, where they are essentially queued and eventually called using BeginInvoke. A problem arises when the control is…
Craig Gidney
  • 17,763
  • 5
  • 68
  • 136
4
votes
3 answers

Error on invoke when the form has closed already

I am trying to display some information on a grid queried from a sql server. The data gathering can take about 10 seconds so I don't want to lock the UI thread. I currently have code like: ThreadPool.QueueUserWorkItem(DataUpdateThread, new…
PeteT
  • 18,754
  • 26
  • 95
  • 132
4
votes
2 answers

How to use BeginInvoke in VB.NET

In C# you use BeginInvoke like this: obj.BeginInvoke((Action)(() => { //do something })); I tried to translate it to VB.NET, and ended up with this code, that seems to work: obj.BeginInvoke( Sub() 'do something' End…
Breeze
  • 2,010
  • 2
  • 32
  • 43
4
votes
1 answer

Why did dispatcher BeginInvoke fail where Control BeginInvoke succeed in C# Windows Forms app?

I originally tried to use the Dispatcher class BeginInvoke method to show a message box on the main UI thread in my C# Windows Forms app. When I used that method the message box did not appear. I set a breakpoint inside the body of the delegate I…
Robert Oschler
  • 14,153
  • 18
  • 94
  • 227
1 2
3
18 19