c# - Creating and showing forms at timed intervals -


i trying create , show forms @ timed interval. form contains picturebox , displays animated gif. @ each interval previous gif(s) closed , new ones created , displayed. able work single forms/gifs, if try show more 1 form @ time, run problems.

here structure of have attempted:

private void m_intervalcountdown_oncountdowncompleted(object sender, eventargs e) {    //the timed event has fired            prepareanddisplaynextforms();  }  private void prepareanddisplaynextforms() {    closepreviousforms();     //i loop through list of gifs , call:    system.drawing.image img = system.drawing.image.fromfile(m_filepath);    form_gif formgif = new form_gif(img);     //i add each form_gif created concurentdictionary           displaygifs();  }  private void closepreviousforms() {    //i loop through list containing forms, , call:    myform.close();    myform.picturebox.dispose();    myform.dispose();     //it turns out have use invoke on form here close it,    //though haven't explicitly created new thread/task, assume when    //timed event fires new thread created internally or something.      //i'm not great @ figuring out when calling dispose necessary, think    //because loaded image picturebox should dispose of it,    //although i'm not certain.  i'm less whether dispose on form    //is required, figured wouldn't hurt much. }    private void displaygifs() {    //i loop through list of form_gif's , try .show() them    //here problem manifests itself.     //if use:    myformgif.show();     //then form doesn't become visible, if move mouse cursor    //over spot form should be, cursor changes "wait" animation      //if use:    myformgif.showdialog();     //this display 1 form @ time, can't show multiple forms @ once.    //i thought might because using same thread showdialog on     //each of forms, , showdialog of first form prevents next 1    //being called.      //so tried:     task t = null;    cancellationtokensource searchtokensource = new cancellationtokensource();     t = task.factory.startnew(() => myformgif.showdialog(), searchtokensource.token);      //but again while works individual gifforms, can't show more 1 @    //a time; if try, invalidoperationexception:  "form    // displayed modally cannot displayed modal dialog box. close form    // before calling showdialog."  } 

my thought if timed event allow me display forms using main thread, call .show() , work out. when tested showing multiple forms on buttonclick event, worked out fine using .show(). when introduce system.timer event, .show() doesn't work out.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -