Today topic is show you how to SendMessage to another window will not responding message!
Explore My Other Channel for More Cool and Valuable Insights
👉 Youtube Learn Tech Tips👉 Tiktok
👉 Facebook:On the multiThread, working with process and GUI for users, you can use SendMessage.
At some time, we want to this window send message to another window.
Win32 API SendMessage will be help you easy do it
On some case:
When we run a program: on the task's search, data compression, image compression, etc ..., We can give another Thread running
On C# language, we have two Timer (one is System.Windows.Forms.Timer, and another is System.Threading.Timer)
If you use System.Windows.Forms.Timer, The GUI will be lock all user action, because this is only one Thread working
If you don't want lock user action, you can try to use System.Threading.Timer. The timer running with another Thread. So you not get locked
// Zidane - huuvi168@gmail.com
// DateTime: 2016-02-09
private const uint TIMER_GLOBAL = 500;
private static System.Threading.Timer _timer_Global;
// Load global Timer
System.Threading.TimerCallback cb =
new System.Threading.TimerCallback(timer_Global_Fn);
// Create the timer. It is autostart, so creating the timer will start it.
_timer_Global = new System.Threading.Timer(cb, null, TIMER_GLOBAL, 1000);
private void timer_Global_Fn(Object obj)
{
// do something here
// ...
}
Chinese version
在多重 thread 下, 希望一邊工作, 一邊把工作進度呈現給使用者. 你可以使用 SendMessage.
有的時候, 我們會希望某一個視窗送一個訊息給另一個視窗.
Win32 API SendMessage 可以完成你想要的功能.
最常遇到的狀況是,
當我們在程式中, 進行 資料壓縮, 影像壓縮 或 資料搜尋 等高時間消耗的工作時,
就必須把這些工作, 交給獨立的 thread 來執行.
一般的情況是, 一條 thread 進行使用者介面操作, 另一條 thread 進行高時間消耗的工作.
兩者的通訊, 則可以使用 Message 進行交流.
如果你使用 System.Windows.Forms.Timer 來處理, 則會 lock 住所有使用者的動作.
因為這個 object 是單一執行緒. 這是假的多工.
高時間消耗工作, 會搶去所有的執行時間, 使得你的視窗無法得到任何有關使用者的動作事件.
而且你也無法在視窗上更新進度.
高時間消耗工作, 又要同時顯示進度. ---> 你需要真的多工
使用 System.Threading.Timer 可以建立一條新的 thread,
然而, 如果你需要在一條工作 thread 進行工作進度的視覺呈現, 你可以使用 SendMessage.
Happy new year. Wishes you healthy, happy, successful and lucky ^^
Thank you for reading this post. I hope you found it helpful and easy to follow. If you have any feedback or
questions about
How to Solve SendMessage Not Responding Issue with System.Threading.Timer ,
please share them in the comments below. I would love to hear from you and discuss this topic further
✋✋✋✋
Webzone Tech Tips, all things
Tech Tips for web development
- I am Zidane, See you next time soon ✋✋✋✋