❔ Update Form in a new Thread!
I created a form with a datagridview.
Now I want to run a powershell command in a new thread and in this new thread I want to add the data from the powershell command in the datagridview.
With normal threads I get an error which says that I can not call the datagridview from the main thread
is there another way doing that?
15 Replies
you cannot touch UI controls outside of the UI thread
to post code to the UI thread, you can use the
Invoke
method on any control from your FormControl.Invoke Method (System.Windows.Forms)
Executes a delegate on the thread that owns the control's underlying window handle.
@jcotton42 I used Invoke with Action and with delegate but nothing works
I mean I get the results at the same time and not one after the other, but it is still locking the UI thread
wdym "locking the UI thread"?
as in the app is not responsive during the operation?
how are you running the powershell?
as in the app is not responsive during the operation?yes! this is what I tried: all of these solutions are locking
sorry, I more meant how you are invoking the powershell code?
the bit that would actually be typing up the UI
not sure what you mean, but maybe you mean this?
yeah that
the UI will be blocked during the entirety of ps.Invoke
correct 🙂
can you help me to make that non-blocking?
there should be an InvokeAsync on it iirc
if not you'll have to shunt it off the UI thread with something like Task.Run
@jcotton42 there is no minimal example you can show 😦 ?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.does anyone have an idea how to do that with threads?
what part do you need help on?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.