|
I have to write a small C# form-based program which parses thru a directory containing data files. For each data file, it takes some time to process.
The problem is that with a directory with many files, my program is like frozen. The program doesn't respond to any mouse clicks or keyboard input. Worse than that, if I click on other applications, and click back to my application, the form doesn't repaint & sometimes, it repaints but Windows says that "This application does not respond" on the title bar. If I just let my application run, it will surely complete after a while.
I tried to alleviate the situation by creating a modeless dialog with a Cancel button. Before I run my lengthy task, I opened this modeless dialog. If the user clicked on the Cancel button, I set a global boolean Cancel variable, which was checked at every iteration of the lengthy task.
To my surprise, the modeless dialog didnt receive any mouse clicks when the lengthy task was in progress. So, there was no way for me to terminate the lengthy operation when it's running.
I certainly need your advice on dealing with time-consuming tasks. I guess that I would have to break down this task into several parts, but don't know how to make them run back-to-back.
Thanks a lot for your help.
|
|
|
|
|
You should do those tasks in a seperate thread. Search this site or google for this topic.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
If you want an example on how to use threads you can see:
http://www.codeproject.com/useritems/WinCount.asp
I have a program that goes thru directories and files on a seperate thread and the UI is responsive.
|
|
|
|
|
|
This is happening because the UI is being processed on the same thread as your code.Try dropping an Application.DoEvents() call into the loop that does the processing and make sure it is going to execute fairly frequently. This will cause your thread to give up control of the processor so other threads can run and other Windows can process their message queues, including yours.
The other option is to put your function that does this processing on another thread.
For an example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cssample/html/vcsamThreadingSample.asp[^]
RageInTheMachine9532
|
|
|
|
|
just create worker threads to do the background work... that way you leave the ui thread free to deal with the ui. just do a search on worker threads on google or here at codeproject.
|
|
|
|
|
Thank you so much, gurus
I haven't given it a shot, but I think that will solve the problem.
|
|
|
|
|
|
does anyone know how can i display a balloon tooltip in C# ?
thanx
shakooosh
|
|
|
|
|
|
A better example - had you searched for "balloon tooltip" on CodeProject - can be found in the article Adding Balloon Windows to a .NET Application[^]. There are other articles that uses IExtenderProvider s to provide balloon tooltips, too. Just search this site.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have been working on a custom tab control and at this poitn everything works and acts like it should EXCEPT for when you first open the designer for my tabcontrol... the designer doesnt see any of the tabs/pages that are assigned to it in the code. In order for it to see them i have to go and add another tabpage to the tabcollection, when this is done it adds the collection of pages to the tabcontrol. After thats done the designer works like it should..... its only on init of the designer that this problems happens. is there an easy way to these items at init? how does one make the init find the associated controls to the tabpage?
i have looked at Magic tabcontrol version 1.7 and pallaControls but this is just a rip of the Magic code (with a few minor changes).
perhaps just a good tutorial on creating custom ParentControlDesigner.
ps. if you would like to see some code or just more info then let me know
thanks for any info.
mb
|
|
|
|
|
perhaps its the problem is that i can not fire events from my custom TabButton control.... after i add a tabpage to my collection i then get focus on those tabpages and then can click on the tabbuttons and everything is just great.... so maybe its an issue about not setting the correct focus?
anyone?
thanks
mb
|
|
|
|
|
nevermind.... i fig it out. i just had to reinit everything from with in the designer. all fixed and working well.
|
|
|
|
|
Hello,
Here is my problem:
I made a custom button, derived from Button. Now, in my custom button I have a MyInfo struct.
I also have two forms, call them Form1 and Form2.
Form1 creates a custom button, myButton. What I want to do is pass myButtons MyInfo struct by reference to Form2 from Form1. I tried to do it like so:
<br />
f2.setInfo(ref myButton.myInfo);<br />
where myInfo is a MyInfo struct.
However, when I compile, I get something like this error:
Cannot pass 'MyButton.myInfo' as ref or out, because 'MyButton.myInfo' is a marshal-by-reference class
How can I pass my struct by reference to this other form?
Thanx for the help
-Flack
|
|
|
|
|
Since System.Windows.Forms.Button inherits from MarshalByRefObject, instances of System.Windows.Forms.Button could be used as cross-process proxies. No field of a potential proxy can be allowed to be passed by reference.
There's a fairly good treatment of it at here[^]
Why do you want to pass the structure by reference?
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
you should probably post some more code for people to be able to help you such as your definition of MyInfo struct and your setInfo function
|
|
|
|
|
Hi,
I have a C# windows app and I need to create a desktop short cut and a IE favorites short cut. Can anyone tell me how to programatically do this? I'd like to do this when my application first runs.
Thanks
|
|
|
|
|
|
I am running Visual Studio .NET 2002. When I create a user control via a project and add a reference to its DLL in a test project it does not appear in the toolbox. How do place my control in the toolbox?
Gary A. Hyslop
|
|
|
|
|
Right-click on the Toolbox and select Customize. Browse to your assembly and check the controls you want to add to the toolbox. There are other ways you can do this using the designer interfaces. See the System.ComponentModel namespace for more information (as well as System.ComponentModel.Design ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How do you do it? Write click on your ToolBox and select Customize ToolBox , then select your dll from .NET Component tab.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
I have written a consle application and wabt to exit the program if the user select the exit program option. Can u please write the code and the namespace details as well.
|
|
|
|
|
See the Environment.Exit method documentation in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It ends the console window as well, I only want to exit the program.
|
|
|
|