c# - Accessing instance of class from another instance that already running -


this question has answer here:

i have 2 project in c# visual studio solution: main , add. both project using different namespace. let say: mainnamespace , addnamespace.

in main project have form had activex windows media player component on it. have open dialog open video , button stop video. dummy button stop video.

    public void button2_click(object sender, eventargs e)     {         stopmovie();     }      public void stopmovie()      {         axwindowsmediaplayer1.ctlcontrols.stop();         messagebox.show("video stoped!");        } 

in add project have function want call stopmovie() function remotely. declare this:

void remotestop() {      mainnamespace.main ff = new mainnamespace.main();      ff.stopmovie(); } 

the code run without error, execute messagebox ("video stoped!") , video still keep running. when press stop button in main stop video. miss here?

thanks.

update: solved

i accessed via form (that running):

        formname remotekill = (formname)application.openforms["formname"];         if (remotekill != null)         {             remotekill.stopmovie();                         } 

mainnamespace.main ff = new mainnamespace.main(); 

this line, suggests, create new main object (which form). creating new form , try stop video within that form. not affect existing form being displayed somewhere , video playing.

you have pass reference of existing main somehow add component make work.


Comments