invoke

Close a form from an external thread using the Invoke method

徘徊边缘 提交于 2019-12-07 09:24:49
问题 I have to close a Form from a thread and I am using the Invoke method of the Form for calling the Close() method. The problem is that when closing, the form is disposed and I get an InvalidOperationExecption wit the message "Invoke or BeginInvoke cannot be called on a control until the window handle has been created.". I have got this exception only when debugging with a "Step Into" in the Close method but I don't want to risk with a possible error on normal running. This is an example code

VB.NET Two different approaches to generic cross-threaded operations; which is better?

≯℡__Kan透↙ 提交于 2019-12-07 04:56:43
问题 VB.NET 2010, .NET 4 Hello, I recently read about using SynchronizationContext objects to control the execution thread for some code. I have been using a generic subroutine to handle (possibly) cross-thread calls for things like updating UI controls that utilize Invoke . I'm an amateur and have a hard time understanding the pros and cons of any particular approach. I am looking for some insight on which approach might be preferable and why. Update: This question is motivated, in part, by

Which C# assembly contains Invoke?

浪子不回头ぞ 提交于 2019-12-07 04:38:30
问题 Alternate question: Why is VS10 so keen to complain about Invoke? In my continuing quest to make my app work become the worlds best C# programmer, I have decided that threads are a Good Thing™. MSDN has a helpful article on making thread-safe calls to controls, but it (and seemingly every other article on the subject) obliquely references a method called Invoke. Sometimes even BeginInvoke, which I've read is to be preferred. All this would be great, if I could get visual studio to recognise

简短总结一下C#里跨线程更新UI

前提是你 提交于 2019-12-07 01:27:06
跨线程更新UI是写多线程程序尤其是通信类的程序经常遇到的问题,这里面主要的问题是冲突,比如数据线程想要更新UI的时候,用户同时也在更新UI,就会出现争用。C#里可以用 Control . CheckForIllegalCrossThreadCalls = false ; 来关闭跨线程检测。但是这样做有一定的风险,容易让程序崩溃。 最好的办法是通过Invoke,这篇博客只是提供一个示例,至于那些线程同步、Invoke和BeginInvoke,Invoke底层实现神马的,有空再说吧。 一个简单的例子如下:(注,Form1 加入了一个名为txt的TextBox) using System ; using System . Collections . Generic ; using System . ComponentModel ; using System . Data ; using System . Drawing ; using System . Linq ; using System . Text ; using System . Windows . Forms ; using System . Threading ; namespace testThread { public partial class Form1 : Form { private delegate void

How to call the __invoke method of a member variable inside a class

送分小仙女□ 提交于 2019-12-06 19:52:14
问题 PHP 5.4.5, here. I'm trying to invoke an object which is stored as a member of some other object. Like this (very roughly) class A { function __invoke () { ... } } class B { private a = new A(); ... $this->a(); <-- runtime error here } This produces a runtime error, of course, because there's no method called a. But if I write the call like this: ($this->a)(); then I get a syntax error. Of course, I can write $this->a->__invoke(); but that seems intolerably ugly, and rather undermines the

what is invoking?

拈花ヽ惹草 提交于 2019-12-06 19:16:41
问题 What is method invoke, control.invoke? What is invoking in general in programming examples : MethodInvoker getValues = new MethodInvoker(delegate() { checkbox1Checked = checkbox1.Checked; textBox6Text = textBox6.Text; textBox7Text = textBox7.Text; textBox3Text = textBox3.Text; textBox1Text = textBox1.Text; textBox4Text = textBox4.Text; richTextBox1Text = richTextBox1.Text; textBox5Text = textBox5.Text; }); if (this.InvokeRequired) { this.Invoke(getValues); } else { getValues(); } And I also

What does 'InvokeRequired' and 'Invoke' mean in .Net?

瘦欲@ 提交于 2019-12-06 15:33:06
I have been working a lot with threading in a few programs I am working on, and I have always been curious as to what exactly something is doing. Take for instance the following code, which is ran from a thread to update the UI: Public Sub UpdateGrid() If Me.InvokeRequired Then Me.Invoke(New MethodInvoker(AddressOf UpdateGrid)) Else DataGridView1.DataSource = dtResults DataGridView1.Refresh() btnRun.Text = "Run Query" btnRun.ForeColor = Color.Black End If End Sub What exactly does the Me.InvokeRequired check for, and what exactly is the Me.Invoke doing? I understand that somehow it gives me

Get a RETURN from a Invoke method

做~自己de王妃 提交于 2019-12-06 09:55:42
I am trying to read value from a listbox item that is on another thread. I tried to make a new method to run the invoke command, I can manage to send a command to the listbox like add via the invoke method but i cant seem to get a response, i cant seem to get the value of the item, i have tried a few ways, once i change it from a void to a string things start to get hairy... thread t1 = new thread(thethread) t1.start() public void thethread() { string text = readListBoxSelected(listBox1) + " lala" ; } public static string readListBoxSelected(ListBox listbox) { if (listbox.InvokeRequired) {

JavaFX : invoking ' Application.launch(args) ' from a method other than main [duplicate]

流过昼夜 提交于 2019-12-06 09:39:20
This question already has answers here : Starting JavaFX from Main method of class which doesn't extend Application (3 answers) Closed 4 years ago . Question Can I call ' Application.launch(args); ' from a method other than main? If so could you provide an example keeping in mind the below context? Background I'm build a learning/teaching, command/text application, that teaches the user about arrays. At the end of the main class, after the major application content has ran, I call ' ViewSiteOrExit.viewSitePromptPuSVM(); ', which gives the user the opposition to either: open the Oracle page on

C#/WinForms: ShowDialog and subsequent Show on Form

时光怂恿深爱的人放手 提交于 2019-12-06 09:22:08
For reasons I think are not relevant here I have one or more Threads that comunicate with a single instance UI (a Form). In the worker threads I need to report progress or input data or simple choices. All of those come from user interaction with the UI and, of course, for M$ .NET, all the UI runs in the main thread. Obviously I need to handle the thread synchronization across the UI (main) thread and the worker ones. I do it by properly verifying InvokeRequired and company. There is a miriad of posts and articles around there discussing incoherences and subtleties in InvokeRequired ,