Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2008

Tip: Looking for answers? Try searching our database.

invisible gui

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave - 16 May 2008 02:01 GMT
I have a program that process files on a hard drive. Everything works fine,
it shows a progress bar as it processes the file. The problem occurs when I
have the program look for files to process on startup. The gui is invisible
untill it processes the files it finds as it startsup. After which it
appears and everything works normally when the next file needs to be
processed.

Is there anyway to tell the program to not look for files untill the
interface is visible? I need a method like onGUIAppears.

Thanks in advance.
Peter Duniho - 16 May 2008 02:14 GMT
> I have a program that process files on a hard drive. Everything works  
> fine,
[quoted text clipped - 8 lines]
> Is there anyway to tell the program to not look for files untill the
> interface is visible? I need a method like onGUIAppears.

It's difficult for me to understand how your GUI can show progress if the  
processing begins after the GUI is shown, but not before.  Perhaps you've  
made a mistake in your initialization by starting the processing before  
some specific initialization within the GUI is done.  The question of  
visibility shouldn't matter.

That said, you can override OnShown() in your form class to know when the  
form is actually being shown and delay your processing until that point.

Pete
Dave - 16 May 2008 03:14 GMT
You misunderstood, I mentioned the progress bar as a reason to why I wanted
to see the form before processing begins. You CAN NOT see the progress bar
on startup.The files are processed correctly even though you can't see the
progress.

I beleive the OnShown() will do what I need. Can you post a short example on
how to use this?

Thanks,

Dave.

>> I have a program that process files on a hard drive. Everything works
>> fine,
[quoted text clipped - 19 lines]
>
> Pete
Mach58 - 16 May 2008 04:19 GMT
>You misunderstood, I mentioned the progress bar as a reason to why I wanted
>to see the form before processing begins. You CAN NOT see the progress bar
[quoted text clipped - 7 lines]
>
>Dave.

Something like this should do:

using System;
using System.Windows.Forms;

class Class1 : Form
{
   bool firsttime = true;
   protected override void OnShown(EventArgs e)
   {
       if (firsttime)
       {
           firsttime = false;
           //  ##put your code here##
           MessageBox.Show("I've been shown! (for the first time)");
       }
       base.OnShown(e);
   }
   static void Main(string[] args)
   {
       Application.Run(new Class1());
   }
}

If you need more help, you'll need to post some code.  Please follow
this guidelines:

http://www.yoda.arachsys.com/csharp/complete.html

Mach
Linda Liu[MSFT] - 16 May 2008 08:44 GMT
Hi Dave,

When a Form is loaded, it's Load event is fired first. The Form won't show
until all lines of code in its Load event handler finish executing. After
that, the Form's Activated event is fired and then the Shown event.

If the Form does some time-consuming work in the Activated or Shown event
handler, the UI of the Form will be blocked, i.e. all controls on the Form
are not painted properly or not responsive. This is because the main UI
thread is busy and doesn't have a chance to paint/refresh the UI of the
Form.

To show a Form and then do some time-consuming work without blocking the
UI, I suggest that you do the time-consuming work in a separate thread. You
can create a Thread instance or call the BeginInvoke method on the delegate
to the time-consuming method to do it, if you're using .NET 1.x.

If you're using .NET 2.0, I recommend you use the BackgroundWorker
component, which provides a concise multiple-threads programming model and
is very easy to use. You can start a BackgroundWorker in the Form's Load
event handler in your practice.

For more information on how to use the BackgroundWorker component, please
refer to the following MSDN document:
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundwork
er.aspx

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Linda Liu[MSFT] - 20 May 2008 07:13 GMT
Hi Dave,

How about the problem now?

If the problem is still not solved, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.