How to use background threads in WinForm to manipulate UI 10

Updated on technology 2024-06-03
6 answers
  1. Anonymous users2024-02-11

    After .NET 2005, threads are not allowed to manipulate the UI directly, otherwise an error will be reported, but it can be solved by delegate.

    For example, the following datareflash is a method in the thread, which needs to refresh the data of the page control, then you can define a delegate to implement, refer to the aunt as follows:

    public void datareflash(string text)

    if (text == "901")

    myinvoke mi = new myinvoke(binddate);Just put the binddate method in the delegate, similar to your settext method, you can write anything in this method, such as assigning a value to a text box, or rebinding the data source of the datagrid, etc.;

  2. Anonymous users2024-02-10

    Use the delegation, or add a sentence in the foreground UI.

    checkforillegalcrossthreadcalls = false;Calls to the wrong thread are not captured.

    The former is more practical, and the latter treats the symptoms rather than the root cause, but both can achieve results.

  3. Anonymous users2024-02-09

    Are you sure to use async? When asynchronous, multithreading is responsible for the creation and operation of threads through the system, and you do not need to operate.

    Guess you're getting the usage of async wrong.

    That form is busy, simply because the thread that created it doesn't have time to spare (e.g. it's busy or looping), so it can't respond to messages.

    Often, what you're doing is not advisable. Because a thread ends when it finishes executing, it is rarely in an idle state for the window to update status messages. To create a form, it is recommended to create it in the main thread as much as possible.

  4. Anonymous users2024-02-08

    You can use the Invoke or BeginInvoke method of the control you want to call to invoke a UI control on a non-UI thread.

  5. Anonymous users2024-02-07

    For the sake of security between threads, try to use delegations. This part is not difficult, you will be able to look at it a little.

  6. Anonymous users2024-02-06

    Methods for program exit:; Just close the current window, if it is not the main form, it is impossible to exit the program, and if there is a managed thread (not the main thread), it cannot be exited cleanly; Force all messages to abort and exit all forms, but if there is a managed thread (not the main thread), it cannot be exited cleanly; Force abort all messages on the calling thread, which also faces the problem that other threads cannot exit correctly; This is the most thorough way to exit, no matter what thread is forced to quit, and the program ends cleanly.

Related questions
13 answers2024-06-03

1) In , modify the program class.

using system; >>>More

5 answers2024-06-03

The Bollinger Bands indicator is divided into high lines, median lines, and low lines. The high line of the Bollinger Bands can be used as a reference for the resistance level, while the low line can be used as a reference for the support range. Under normal circumstances, when the three lines of the Bollinger Bands indicator are in a downward trend, and the stock price is running between the median line and the low line, it means that the stock price is in the ** trend. >>>More

5 answers2024-06-03

1. When ** runs in the area between the middle and upper rails of the Bollinger Bands, as long as the middle rail is not broken, it means that the market is in the bulls**, and only consider buying on dips, not shorting. >>>More

5 answers2024-06-03

It's not clear whether black holes really exist or not, but theoretically a black hole is a strange object with infinite mass and infinitely small size, which means that a black hole is an infinite star, and it can attract almost anything, including light, and it can't escape its attraction. This is the black hole. The other side of the newly discovered black hole may be a white hole, which is completely opposite to the nature of a black hole, but this is just an inference >>>More

10 answers2024-06-03

Hello, Gan's line is formed by the combination of the principle of percentage and the principle of geometric angles, it is a set of technical analysis theory created by the analysis of the general trend of Gann. The Gan line starts from a point and draws multiple straight lines backwards according to a certain angle, so the Gan line can also be an angle line. >>>More