SetWindowPos even when the main thread is blocked?What is the difference between a process and a thread?When to use struct?“implements Runnable” vs “extends Thread” in JavaHow do I update the GUI from another thread?What is thread safe or non-thread safe in PHP?What is a daemon thread in Java?How to use threading in Python?What is the main thread in GCD?Android Xamarin Thread.Sleep on main thread complete blocks all threadsThread.Sleep why not block the thread on example
Can a person survive on blood in place of water?
How to reverse input order?
Which European Languages are not Indo-European?
Does this strict reading of the rules allow both Extra Attack and the Thirsting Blade warlock invocation to be used together?
Python program to take in two strings and print the larger string
Alternatives to achieve certain output format
Is there an online tool which supports shared writing?
Why didn't Thanos use the Time Stone to stop the Avengers' plan?
Sankey diagram: not getting the hang of it
USPS Back Room - Trespassing?
Why most published works in medical imaging try reducing false positives?
Of strange atmospheres - the survivable but unbreathable
Why are GND pads often only connected by four traces?
When the Torah was almost lost and one (or several) Rabbis saved it?
Popcorn is the only acceptable snack to consume while watching a movie
My employer faked my resume to acquire projects
Can I connect my older mathematica front-end to the free wolfram engine?
Where have Brexit voters gone?
What is a Power on Reset IC?
NIntegrate doesn't evaluate
Why does Mjolnir fall down in Age of Ultron but not in Endgame?
What was the idiom for something that we take without a doubt?
Is it rude to call a professor by their last name with no prefix in a non-academic setting?
Why were helmets and other body armour not commonplace in the 1800s?
SetWindowPos even when the main thread is blocked?
What is the difference between a process and a thread?When to use struct?“implements Runnable” vs “extends Thread” in JavaHow do I update the GUI from another thread?What is thread safe or non-thread safe in PHP?What is a daemon thread in Java?How to use threading in Python?What is the main thread in GCD?Android Xamarin Thread.Sleep on main thread complete blocks all threadsThread.Sleep why not block the thread on example
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to make my program move itself via a call to SetWindowPos every 10 milliseconds, to follow the cursor. Problem is, when my program's main thread is blocked by a Thread.Sleep(), the window stops moving.
I put the call to SetWindowPos into a secondary System.Thread, but it's still blocked. It appears that SetWindowPos is always handled by the thread that owns the window. So if my main thread is busy, the window can't be moved, even if the request is sent from a different thread.
Is there an alternative way to move a window, even when the thread that owns the window is busy? Thanks!
c# multithreading setwindowpos
add a comment |
I'm trying to make my program move itself via a call to SetWindowPos every 10 milliseconds, to follow the cursor. Problem is, when my program's main thread is blocked by a Thread.Sleep(), the window stops moving.
I put the call to SetWindowPos into a secondary System.Thread, but it's still blocked. It appears that SetWindowPos is always handled by the thread that owns the window. So if my main thread is busy, the window can't be moved, even if the request is sent from a different thread.
Is there an alternative way to move a window, even when the thread that owns the window is busy? Thanks!
c# multithreading setwindowpos
add a comment |
I'm trying to make my program move itself via a call to SetWindowPos every 10 milliseconds, to follow the cursor. Problem is, when my program's main thread is blocked by a Thread.Sleep(), the window stops moving.
I put the call to SetWindowPos into a secondary System.Thread, but it's still blocked. It appears that SetWindowPos is always handled by the thread that owns the window. So if my main thread is busy, the window can't be moved, even if the request is sent from a different thread.
Is there an alternative way to move a window, even when the thread that owns the window is busy? Thanks!
c# multithreading setwindowpos
I'm trying to make my program move itself via a call to SetWindowPos every 10 milliseconds, to follow the cursor. Problem is, when my program's main thread is blocked by a Thread.Sleep(), the window stops moving.
I put the call to SetWindowPos into a secondary System.Thread, but it's still blocked. It appears that SetWindowPos is always handled by the thread that owns the window. So if my main thread is busy, the window can't be moved, even if the request is sent from a different thread.
Is there an alternative way to move a window, even when the thread that owns the window is busy? Thanks!
c# multithreading setwindowpos
c# multithreading setwindowpos
edited Mar 24 at 1:41
user2236034
asked Mar 24 at 1:35
user2236034user2236034
6219
6219
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I don't believe so. All UI operations must be performed on the primary application thread which is known as the UI thread in a GUI app. Whether it is a button click event; mouse move; scroll; paint etc including move window, these operations are queued in the applications message queue (sort of like a FIFO buffer that Windows maintains for all apps) which must be processed by the UI thread.
If say a button click event takes a long time becuase the programmer decided to perform a lengthy database operation in the same thread as the callback, then the UI will freeze until the callback is complete which happens to be the database code.
Similarly if somewhere in your UI thread code you have a Thread.Sleep()
, then the UI will also freeze during the same period.
Alternatives
You might want to consider moving lengthy operations to another thread or go the easy contempory and recommended way and use async/await
. Doing so allows you to perform the lengthy operation without blocking the UI.
Timers
Also, consider using a Timer
instead of Thread.Sleep()
or equivalent as an alternative to moving the window 100 times a second. Be sure to use the right timer for GUI apps as .NET defines at least four (4) I believe and not all are suitable by default (if at all) for GUI apps.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319984%2fsetwindowpos-even-when-the-main-thread-is-blocked%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I don't believe so. All UI operations must be performed on the primary application thread which is known as the UI thread in a GUI app. Whether it is a button click event; mouse move; scroll; paint etc including move window, these operations are queued in the applications message queue (sort of like a FIFO buffer that Windows maintains for all apps) which must be processed by the UI thread.
If say a button click event takes a long time becuase the programmer decided to perform a lengthy database operation in the same thread as the callback, then the UI will freeze until the callback is complete which happens to be the database code.
Similarly if somewhere in your UI thread code you have a Thread.Sleep()
, then the UI will also freeze during the same period.
Alternatives
You might want to consider moving lengthy operations to another thread or go the easy contempory and recommended way and use async/await
. Doing so allows you to perform the lengthy operation without blocking the UI.
Timers
Also, consider using a Timer
instead of Thread.Sleep()
or equivalent as an alternative to moving the window 100 times a second. Be sure to use the right timer for GUI apps as .NET defines at least four (4) I believe and not all are suitable by default (if at all) for GUI apps.
add a comment |
I don't believe so. All UI operations must be performed on the primary application thread which is known as the UI thread in a GUI app. Whether it is a button click event; mouse move; scroll; paint etc including move window, these operations are queued in the applications message queue (sort of like a FIFO buffer that Windows maintains for all apps) which must be processed by the UI thread.
If say a button click event takes a long time becuase the programmer decided to perform a lengthy database operation in the same thread as the callback, then the UI will freeze until the callback is complete which happens to be the database code.
Similarly if somewhere in your UI thread code you have a Thread.Sleep()
, then the UI will also freeze during the same period.
Alternatives
You might want to consider moving lengthy operations to another thread or go the easy contempory and recommended way and use async/await
. Doing so allows you to perform the lengthy operation without blocking the UI.
Timers
Also, consider using a Timer
instead of Thread.Sleep()
or equivalent as an alternative to moving the window 100 times a second. Be sure to use the right timer for GUI apps as .NET defines at least four (4) I believe and not all are suitable by default (if at all) for GUI apps.
add a comment |
I don't believe so. All UI operations must be performed on the primary application thread which is known as the UI thread in a GUI app. Whether it is a button click event; mouse move; scroll; paint etc including move window, these operations are queued in the applications message queue (sort of like a FIFO buffer that Windows maintains for all apps) which must be processed by the UI thread.
If say a button click event takes a long time becuase the programmer decided to perform a lengthy database operation in the same thread as the callback, then the UI will freeze until the callback is complete which happens to be the database code.
Similarly if somewhere in your UI thread code you have a Thread.Sleep()
, then the UI will also freeze during the same period.
Alternatives
You might want to consider moving lengthy operations to another thread or go the easy contempory and recommended way and use async/await
. Doing so allows you to perform the lengthy operation without blocking the UI.
Timers
Also, consider using a Timer
instead of Thread.Sleep()
or equivalent as an alternative to moving the window 100 times a second. Be sure to use the right timer for GUI apps as .NET defines at least four (4) I believe and not all are suitable by default (if at all) for GUI apps.
I don't believe so. All UI operations must be performed on the primary application thread which is known as the UI thread in a GUI app. Whether it is a button click event; mouse move; scroll; paint etc including move window, these operations are queued in the applications message queue (sort of like a FIFO buffer that Windows maintains for all apps) which must be processed by the UI thread.
If say a button click event takes a long time becuase the programmer decided to perform a lengthy database operation in the same thread as the callback, then the UI will freeze until the callback is complete which happens to be the database code.
Similarly if somewhere in your UI thread code you have a Thread.Sleep()
, then the UI will also freeze during the same period.
Alternatives
You might want to consider moving lengthy operations to another thread or go the easy contempory and recommended way and use async/await
. Doing so allows you to perform the lengthy operation without blocking the UI.
Timers
Also, consider using a Timer
instead of Thread.Sleep()
or equivalent as an alternative to moving the window 100 times a second. Be sure to use the right timer for GUI apps as .NET defines at least four (4) I believe and not all are suitable by default (if at all) for GUI apps.
edited Mar 24 at 2:05
answered Mar 24 at 1:50
MickyDMickyD
11.2k63454
11.2k63454
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319984%2fsetwindowpos-even-when-the-main-thread-is-blocked%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown