so I've been seeing applications run in the background in the task manager, but when I create an application it displays in the apps section(here's what I mean):
But here is what I would like to achieve(to make it a background process):
Thanks, all help is appreciated!
Honestly I do not think this is possible using normal development methods. I mean it's a form, it cant run in the background because it has a user interface. Why do you think you need to run a form in the background anyway?
Just spit balling here: Maybe you can implement just the actions you need in a Background process thread that is created in the form, then close the form. If the form runs in its own thread, perhaps you need to set the priority on the thread lower.
Related
I am trying to make a windows form appliation that displays all the Tasks that are running while they are running. I want to stop tasks individually if I want to. I have the application working as a console application but when I try to build it as a windows form application it screws up. Here is how my code works.
Loop
Make a task
store it in a list
start the task=
End Loop
I want to display this list in a listView in my form and update it every few seconds displaying the name and status of this task.Can somebody help me with that or suggest good reads to study multithreading.
Thanks.
I have the application working as a console application but when I try to build it as a windows form application it screws up.
Provided that you didn't change your logic during the port to Windows Forms, this is likely due to updating the Windows Forms controls from the background thread within your Task.
You can only use Windows Forms controls from the main (UI) thread, and not from a background thread. If you want to perform an update to the UI, you need to use Control.Invoke or Control.BeginInvoke to marshal the call back onto the UI thread.
I need to make a WinForm of mine flash to alert the user, and I want to accomplish this by changing the background color from the default to red, and back again every second for 5 seconds. During this 5 seconds, I want to be able to use the form, which makes me think that I should put the flashing code in a different thread, BUT, I believe I will encounter problems because the flashing code will try to modify the form, which was created on a different thread.
What is the best way to accomplish my goal of creating a flashing WinForm?
Thanks!
You need to use a System.Windows.Forms.Timer.
How about using a timer and change the form's background colour in the event handler?
If you want to modify the WinForm from another thread, you can use the .Invoke() method of the form. This method allows another thread to invoke the execution of a method in the form thread.
Se documentation for examples:
MSDN: Control.Invoke
I am attempting to write a specialized onscreen keyboard (OSK) for an application I'm writing in C#. To facilitate this, I've created a form which has several buttons on it representing keys, and clicking them calls SendKeys and sends out the appropriate keys.
This form is owned by the main window that is shown when the application first starts, using the Owner property. This way, the OSK pops up whenever the user focuses the application, and it stays on top of the main window if it said main window is dragged over it.
This all works great, but because I have modal dialogs that I also want to use with the OSK, I attempted to create it in a separate thread, complete with its own message loop (via Application.Run) so it could still be usable with any modal dialogs in the main thread.
The problem with this is that, obviously, being in a separate thread can cause InvalidOperationExceptions because of cross-threaded calls. One specific example of this is when calling Application.Run(osk) from the new thread, a cross thread error occurs because it is attempting to update the window's handle with the owner (the main window).
My question is, is it possible to have an owned form on a thread that is separate from the owner in a safe manner? And, if failing that, is it possible to emulate an owned form's characteristics (namely being Always On Top for only the main window, and popping up when the main window is focused)?
Thanks, and sorry if this is confusing.
I think this is actually a bug in Windows Forms. Somewhat inevitable due to the way it checks for access to the Handle property by the wrong thread. The SDK docs for SetParent are not explicit about it, it states the requirement is that both windows belong to the same application. No mention of having to belong to the same thread. I know for a fact that the 'same application' requirement is not hard, there's appcompat code in Windows that makes this work for windows from different processes. Adobe Acrobat ab/used this for a long time. Which definitely absolves the 'same thread' requirement.
Well, punt the problem and try it out. Set Control.CheckForIllegalCrossThreadCalls to false before you set the owner, back to true afterward. And test the heck out of it. If you have trouble then try pinvoking SetParent() directly instead of setting the Owner. Windows Forms actually uses SetWindowLongPtr which is not recommended by the SDK.
I'll take a stab at this. Try running the OSK as a separate process.
Try using ShowDialog for the OSK as well instead of Application.Run - ShowDialog creates a message loop and ends it when the window is closed, and perhaps will solve your problems.
new Thread(() => new OSK().ShowDialog());
Why not use Control.Invoke to make cross-threaded calls to avoid InvalidOperationException?
lets say you are adding a feature to an old and running windows form application now the whole application is running in one thread and the application is really big and have many forms so you cant refract it to run in multithreads, now the application gui freeze everytime you make a process , is there is any way to have an indicator that its loading or in progress while its freezing ? without changing the whole design of the software to support threads etc ?
by the way i dont want it to stop freezing its ok to freeze i just want it to to indicate that its doing something !
any idea would be appreciated, thanks...
See BackGroundWorker componet if application is written using .net 2.0 or higher version.
You can set the form's Cursor property to Cursors.WaitCursor upon starting the long running action, and reset it to Cursors.Default upon finish. While your action executes you can call Application.DoEvents() but it may cause side effects if other events trigger in the mean time.
When I click on anywhere on my application when the application is busy it changes the cursor into a generic wait cursor. Is there anyway I can code it for an animated cursor?
This is because you must be doing some heavy operation on main UI thread. Do your processing in background (in separate thread).
You may use BackgroundWorker or Thread class to achieve this.
Windows will always use the generic "busy" cursor if the user tries to interact with it and your application is not responding.
The solution to this is to not do processing on the UI thread - do it on other threads, so your UI remains responsive.
If your UI is still responding, you can set a custom cursor to indicate that your application is busy processing.
if you are using the windows application in ASP.NET then there is a option realted to cursor in properties of the form(nit clearlly remember, it was like wait.cursor). You can use that to display the custom cursor at the time of processing also.