Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am developing a C# apps with callback functions.
When the app gets a message, a callback function is triggered and opens a form to display the contents of the message. I do that with .Show() and .BringToFront().
But the new form window, that is opened is frozen. I can't click buttons or even close the window. It remains in the background.
Can somebody tell me why this is happening?
I am using visual studio 2019.
The callback function:
public void currentSelectedCharacteristic_ValueChanged3(GattCharacteristic sender, GattValueChangedEventArgs args)
{
Allgemein.HinweisFenster.Show();
Allgemein.HinweisFenster.BringToFront();
}
We need more details to solve. But i can say that there is a process that blocks your main thread. Try to use 'Application.DoEvent();' or move your code that blocks your thread to another thread. And consider using 'background worker' for this.
Please refer to this thread for more details.
You should also consider that for Windows application, you have to be aware of threads manipulation, thus you have always one GUI thread that can be impacted by your calls flow.
So a rule of thumb is to know how your threads work inside your application.
Generally speaking, Frozen windows are often a sign of GUI thread block.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a problem with a project. After I close my program it won't start anymore because it is still half running in the background.
Sideinfos:
I use threads to asynchronously send refreshing values to other clients via multicast.
How can I stop the threads, so they won't run in the background and I can restart the program?
When you start a thread, you can just set the IsBackground property to true so that it does not survive the death of the other threads.
var thread = new Thread(SendAndReceive);
thread.IsBackground = true;
thread.Start();
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am developing a system that is based on WPF.
the UI need to let user compi and process.
There is a function inside,Ability to perform user compilation
So I can't control the user if user need to import third party dll
I use a Thread to implement this function.
But now there is a problem, if the user calls the window inside the dll, the windows will freezes.
Main
int main()
{
Thread th = new Thread(thread);
th.Start();
}
void thread()
{
LoadLibrary("C:\\123\windows.dll");
StartTest(dll_windows);
}
DLL
public static dll_windows()
{
ShowWindow();
}
In most, if not all frameworks I have seen across many languages, UI elements must be created on the UI thread. Creating them from another thread will lead to all kinds of problems.
Although you did not say what framework you use, I'm willing to bet it also goes for your framework. All your UI elements must be created from the UI thread.
Do work on the other thread, signal when it's done and then create the UI from the UI thread.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a program that loads data from a SharePoint site. It loads txt files, xml files, etc. Any of these "load" actions can take a lot of time because of the user's connectivity to the SharePoint. Therefore the whole windows form UI gets unresponsive until the data is loaded.
So I would like to know how can I easily create a thread for that "retrieval" of information while the whole windows forms UI still works and is operative.
You have a few options. I'm not going to provide exact code for any of them, but, I will provide you with research topics.
You can use a BackgroundWorker, Task.Run() or manage your own threading by doing Thread.Start(). Do you need to fire off an event when the downloading is finished? If so, you can do something like this:
var task = new Task(() => DoSomething());
task.ContinueWith(() => SignalDone(), TaskScheduler.FromCurrentSynchronizationContext());
task.Run();
The ContinueWith and TaskScheduler.FromCurrentSynchronizationContext will ensure that the signaling will be done on the UI thread to minimize race conditions. You're on your own if you're doing databinding to anything being populated.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Can you please point me into the right direction?
I want to edit other application textbox or click, programmatically. For example, in a web sites, I can edit elements and invoke button clicks.
I have no idea how to do this, but I can move mouse and use keyboard run time is it possible to edit other application's textbox ?
I have C++, VB.NET, and C# knowledge - any suggestions or sample code?
Thanks.
There is no easy way to do this, but it is possible. You will dig through the Win32 Api to get what you need. There will be a lot code needed for this, too much to put in sample here.
You will need to start with finding the window you want. This could be accomplished with FindWindowEx. When you have the window, you can enumerate the child controls using EnumChildWindows.
When you finally get the handle to the control you need, you can hook up to the windows message subsystem and send a WM_SETTEXT message using the SendMessage function. There is a wrapper function available: SetWindowText but the documentation clearly states that it will NOT work for windows of other applications.
Be prepared for a lot of digging around in the Win Api. You will probably run into issues regarding security in newer windows OS's. When you get it to run the functionality will be highly depending on the OS, UAC settings etc.
I remember doing this once, 15 years ago in Windows 98, even then it was problematic! So good luck!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 8 years ago.
Improve this question
through every step of my very long-code scheduling processing, I write down the result to a richTextBox, with lines that might exceeds thousands of lines, the application falls in the "not responding status", i discovered this problem by chance just when i disable this step. But, i still need a way to get a complete description of my app processing history, do you have any alternative suggestions
my code seems like that:
public void mycode()
{
//code part one
richTextBox1.text += "result is: abc";
//code part two
richTextBox1.text += "result is: efg";
//code part three
richTextBox1.text += "result is: hij";
}
I would suggest you move your long running task to a separate thread. Any other approach will give you pain in the long run. Trying to keep a GUI updated properly and responding to events while running a long task in the GUI thread itself is so error-prone that you're better off not going there.
Read this article here, it's quite clear as a starting point on multithreading in WinForms GUIs: http://msdn.microsoft.com/en-us/library/vstudio/ms171728(v=vs.100).aspx