The first topic is What wrong with my InvokeRequied
I followed the answer that he recommended it to me but I found a new problem.
The result of below picture is cross thread exception.
What is wrong with my code ?
How to solve this problem ?

The first topic is What wrong with my InvokeRequied
I followed the answer that he recommended it to me but I found a new problem.
The result of below picture is cross thread exception.
What is wrong with my code ?
How to solve this problem ?

Copyright © 2021 Jogjafile Inc.
According to MSDN
InvokeRequiredcan returnfalseeven in cases whereInvokeRequiredshould betrue- namely in the case that you accessInvokeRequiredbefore theHandleof that control/form (or a parent of it) has been created.Basically your check is incomplete which leads to the result you see.
You need to check
IsHandleCreated- if that isfalsethen you would need to useInvoke/BeginInvokeregardless of whatInvokeRequiredreturns.[UPDATE] BUT: This usually won't work robustly since
Invoke/BeginInvokecheck which thread createdHandleto do their magic... [/UPDATE]Only if
IsHandleCreatedistrueyou act based on whatInvokeRequiredreturns - something along the lines of:[UPDATE]
Thus the following is important to avoid this problem
Always make sure that the
Handleis already created BEFORE the first access on a thread other than the UI thread.According to MSDN you just need to reference
control.Handlein the UI thread to force it being created - in your code this must happen BEFORE the very first time you access that control/form from any thread that is not the UI thread.[/UPDATE]