begininvoke

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

别等时光非礼了梦想. 提交于 2019-11-26 22:39:27
问题 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) { if (varControl.InvokeRequired) { varControl.BeginInvoke(new MethodInvoker(() => readControlText(varControl))); } else { string varText = varControl.Text; return varText; } } Edit: I guess having BeginInvoke is not nessecary in this case as i need

Must every BeginInvoke be followed by an EndInvoke?

℡╲_俬逩灬. 提交于 2019-11-26 20:33:40
问题 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 general case of asynchronous delegates, states something different: No matter which technique you use, always call EndInvoke to complete your asynchronous call. These two seem to be in direct conflict. Which is true? Can someone explain? see also, a

Dispatcher Invoke(…) vs BeginInvoke(…) confusion

假装没事ソ 提交于 2019-11-26 12:58:07
问题 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 Invoke. But this doesn\'t solve my confusion. Here\'s the sample code I\'m talking about: public class CounterTextBox : TextBox { private int _number; public void Start() { (new Action(Count)).BeginInvoke(null, null); } private void Count() {

System.Windows.Threading.Dispatcher and WinForms?

烈酒焚心 提交于 2019-11-26 12:32:12
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 Control.BeginInvoke() , but it seems clumsy to create a control only to reference the originating thread. You can use Dispatcher even in a WinForms app. If you are sure to be on a UI thread (e.g. in an button.Click handler), Dispatcher.CurrentDispatcher gives you the UI thread dispatcher that you can later use to dispatch from background threads to the

Is Delegate.EndInvoke() really necessary?

别说谁变了你拦得住时间么 提交于 2019-11-26 09:48:17
问题 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 EndInvoke. Also I\'ve deployed production code using only BeginInvoke and there doesn\'t appear to be any memory issues. The way I\'ve used BeginInvoke is generally with threads that I don\'t care about when they finish or how long they take to process.

Where are CLR-defined methods like [delegate].BeginInvoke documented? [closed]

拥有回忆 提交于 2019-11-26 09:34:24
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . [EDIT, Completely rephrased:] Seems like my question was poorly worded indeed, and poorly received too. So I hope that this complete rephrasing helps... MSDN tells clearly specifies: Control.BeginInvoke() Executes a delegate on the thread that the control\'s handle was created on, normally this would be the GUI

Display progress bar while doing some work in C#?

ぐ巨炮叔叔 提交于 2019-11-26 09:17:57
问题 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 ProgressForm(this)) { //Do Some Work } Now there are many ways to solve the issue, like using BeginInvoke , wait for the task to complete and call EndInvoke . Or using the BackgroundWorker or Threads . I am having some issues with the EndInvoke,

System.Windows.Threading.Dispatcher and WinForms?

守給你的承諾、 提交于 2019-11-26 03:36:20
问题 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 Control.BeginInvoke(), but it seems clumsy to create a control only to reference the originating thread. 回答1: You can use Dispatcher even in a WinForms app. If you are sure to be on a UI thread (e.g. in an button.Click handler), Dispatcher

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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-25 22:02:21
问题 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 delegate? or are they the same thing? 回答1: Do you mean Delegate.Invoke/BeginInvoke or Control.Invoke/BeginInvoke? Delegate.Invoke: Executes synchronously, on the same thread. Delegate.BeginInvoke: Executes asynchronously, on a threadpool thread. Control