Questions tagged [invokerequired]

InvokeRequired refers to the .NET WinForms Control.InvokeRequired method, which needs to be checked before UI updates are made.

In .NET WinForms Control.InvokeRequired needs to be checked before UI updates are made.

It will be True when the handle has been created and the current thread is not the thread on which the control was created.

When it is True, you need to perform the UI update using a delegate call through Control.Invoke which will marshal the delegate onto the UI thread.

MSDN link - Note that other frameworks can implement this concept using the System.ComponentModel.ISynchronizeInvoke interface (though something is still needed to actually marshal the calls back to another thread).

96 questions
0
votes
0 answers

Winform check Invokerequired for each tabpages in a tabcontrol

I have a winform app in the main form has a tabcontrol, one thread will create or remove tabpages very frequently.And some other background threads will get data and need to visit each tabpage's control inside it. the code is here and can…
Bubble
  • 47
  • 1
  • 5
0
votes
2 answers

C# wpf dispatcher confusion

how should i go about porting this code to wpf? public void ChangeTextBox(string txt) { if (textBox1.InvokeRequired) { Invoke(new UpdateText(ChangeTextBox), new object[] { txt }); } else { …
Victornor
  • 83
  • 1
  • 8
0
votes
2 answers

Updating array of labels from backgroundworkers

I am trying to update an array of Labels which are on a form from a backgroundworker. Here is my code: for (int i = 0; i < 6; i++) { if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate { …
NESHOM
  • 899
  • 16
  • 46
0
votes
2 answers

GUI cross-thread safety in .NET when reading but NOT updating DataGridView Control

While there are a ton of questions/answers on SO regarding updating a GUI control from a worker thread using Control.Invoke, I haven't been able to get clarity on the topic of reading data from a control without updating it. Example: I have a…
blitz_jones
  • 1,048
  • 2
  • 10
  • 22
0
votes
2 answers

Thread safe invoke on a listbox woes

First post here. Long time lurker though. I'll get right to it. My little side project here is an application that will scrape postings off of craigslist. Once scraped, the listing data gets sent to a listbox in "Form1". I have created a worker…
Wariv
  • 15
  • 6
0
votes
1 answer

Why doesn't my Textbox update with Thread-safe calls using InvokeRequired?

UpDate1: More detail: Thread 1 and 2 must be continuously active. Thread 1 is updating its GUI and doing HTTP POSTs. Thread 2 is using HTTPListener for incoming HTTP POSTs, and supplying that data to Thread 1. So the GUI needs to be display with…
Kent
  • 59
  • 1
  • 7
0
votes
3 answers

Events and Multithreaded code in .NET

Project is C#. So I have a bunch of multithreaded code that is designed to be run as a library. It's in a seperate project from the UI. My library has a central object that needs to be created before anything that would fire off events is…
Joel Barsotti
  • 3,031
  • 7
  • 35
  • 59
0
votes
1 answer

'Invoke' and 'BeginInvoke' are called but never resolved

I am taking care of the GUI thread of a piece of software. I have to display inside a GridView data that needs to be constantly polled from the underlying APIs. I created a method called Sync() which updates the data, and I tried to make it thread…
0
votes
1 answer

Method for replacing INVOKE

Is there a way around using the Invoke and InvokeRequired methods for objects which were created in other threads? Is there a method which is more direct and less memory intensive? Perhaps a state machine or thread controls? Am I wasting my time…
turbonate
  • 159
  • 2
  • 13
0
votes
1 answer

Invoke Windows Form Thread and Sleeping

I have a managed c++ application that I start a new thread to do some stuff and update some text boxes, it loops and sleeps at the end of every loop. Because of it sleeping I needed to have it in a new thread so the UI doesn't crash. Then I realized…
user1670407
0
votes
2 answers

Control.Invoke never calls delegate

I'm working with the DevExpress XtraGrid control. I have a routine that goes thru and adds all the controls on the current form dynamically, and launches on a seperate thread the routine for a given control to initialize it to the value that will be…
Brian G Swanson
  • 1,039
  • 7
  • 17
0
votes
2 answers

Cross thread InvalidOperationException, InvokeRequired == false when accessed by 2 threads simultanously

A control is accessed by two worker threads, the 2nd before the first has completed it's work on the control. The second thread (9) gets InvokeRequired == false, and the first thread (17) then gets the exception when calling .Refresh on a…
bretddog
  • 5,411
  • 11
  • 63
  • 111
0
votes
1 answer

InvokeRequired=true on Main thread?

I am debugging a WinForm control and it returns InvokeRequired = true although i am on Main thread. Is it possible for a control to be child of a non-UI thread? I thought control which is an UI component can only be child of UI thread.
user156144
  • 2,215
  • 4
  • 29
  • 40
0
votes
1 answer

not yet another invoke required ( + background worker)

ive searched high and low for invoke required related posts on stack overflow.. its helped me learn a lot.. but i have a couple of questions.. not only relating to invoke required but also background worker.. bear with me please.. :) my application…
AweSIM
  • 1,651
  • 4
  • 18
  • 37
0
votes
1 answer

Strange behavior of threads

I’m writing an application that communicates with some hardware using the MODBUS protocol. I'm using this sample from Code Project. While trying to optimize the code (mainly the PollFunction function), I've encountered with a very strange threads…
toy4fun
  • 839
  • 2
  • 14
  • 33