c# - Splash screen does not return focus to main form -


i everyone. have problem focus when using splash screen. using vs2008, .net framework 2.0. also, have linked project visualbasic.dll since use applicationservices manage single instance app , splash screen.

here code snippet simplified of tried debugging.

namespace myproject {     public class bootstrap     {         /// <summary>         /// main entry point of application. creates default          /// configuration bean , creates , show mdi         /// container.         /// </summary>         [stathread]         static void main(string[] args)         {             // creates new app manages single instance background work             application.enablevisualstyles();             application.setcompatibletextrenderingdefault(false);             app myapp = new app();             myapp.run(args);         }     }      public class app : windowsformsapplicationbase     {         public app()             : base()         {             // make single-instance application             this.issingleinstance = true;             this.enablevisualstyles = true;              // there other things available in vb application model,             // instance shutdown style:             this.shutdownstyle = microsoft.visualbasic.applicationservices.shutdownmode.aftermainformcloses;              // add startupnextinstance handler             this.startupnextinstance += new startupnextinstanceeventhandler(this.siapp_startupnextinstance);         }          protected override void oncreatesplashscreen()         {             this.splashscreen = new mymainform();             this.splashscreen.startposition = formstartposition.centerscreen;         }         protected override void oncreatemainform()         {             // initialization here             //...             system.threading.thread.sleep(5000);  // test             // create main form, splash screen automatically close             this.mainform = new form1();         }         /// <summary>         /// called additional instances. application model call          /// function, , terminate additional instance when returns.         /// </summary>         /// <param name="eventargs"></param>         protected void siapp_startupnextinstance(object sender,             startupnextinstanceeventargs eventargs)         {             // copy arguments string array             string[] args = new string[eventargs.commandline.count];             eventargs.commandline.copyto(args, 0);              // create argument array invoke method             object[] parameters = new object[2];             parameters[0] = this.mainform;             parameters[1] = args;              // need use invoke b/c being called thread.             this.mainform.invoke(new mymainform.processparametersdelegate(                 ((mymainform)this.mainform).processparameters),                 parameters);         }     } } 

now, happens that, when start application, splash screen shows expected, when destroyed, not return focus main form (form1 in test). mainform flashes orange in taskbar. if launch application ide (vs2008), focus works fine. using xp pro. also, main form not on top of every other windows. if comment out oncreatesplashscreen() method, application gets focus normally.

to test normal execution, using vs command prompt launch application. using release version of project.

any ideas?

edit: handle startupnextinstance event send command-line arguments main form. test purposes, removed here.

edit: added bit more code. have full extent of bootstrap.

the question not in detail.

1) relationship between splashscreen , main form of application?

2) how splashscreen automatically close?

i'm sure problem here main form had started loading in background while splashscreen yet close. due bad timing, main form loads in background , splashscreen unloads... hence flash in taskbar.

make them appear in serial controlled manner. there many ways. cannot suggest how since hardly detail has been provided. vb doing in project, how many threads working, custom forms used here.. etc.

edit:

algorithm implement splash screen (imho) :)

1) create custom form - splash screen

2) run on separate thread. implement it's behaviour like.

3) in splash screen form, write handler capture custom unload event handler closes splash screen form.

4) now, in main thread, create main app form. set visible property false.

5) write handler of main form's load event. in handler, fire event splash screen unload. then, make main form visible.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -