Hi,
I have 3 application
1- C# window application1
2- C# window application2
3- Class library
I am Passing data from application 1 to class library and I want this data from application 2. But I am not getting
For ex My class library have one class
public class1
{
public bool Flag = false;
public void hello(bool f)
{
Flag = f;
}
}
application 1
class1 cs = new class1();
cs.hello(true);
but from application 2 I am always getting Flag value false event I passed true
Please suggest how can i persist value of flag.
Thanks
Loading
VulpesPosted Jan 24, 2013, 12:46 PM
If you don't, then I'd add it because otherwise the default threading model for COM interop is MTA.
If you already have the attribute, are you explicitly starting any threads in your application?
If you are, then try calling this method before starting the thread:
' t is the new thread object
t.SetApartmentState(ApartmentState.STA)
Areeb QuaziPosted Jan 24, 2013, 12:06 PM
Thanks for your reply, I really appreciate you help.
My problem is I migrated vb6 activeX application into .net and exposed it as ActiveX exe. Which takes data from java web application and pass it to vb.net application. Now i used Remoting now I am able to pass data from Java --> vb.net (ActiveX) --> to vb.net windows application
but when I am trying to assign this value to any text box then I am getting error
An error occurred creating the form. See Exception.InnerException for details. The error is: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
and not able to rasise any event of
VulpesPosted Jan 24, 2013, 10:39 AM
Notice that even though it's the same dll, it's loaded into different Application Domains and so even if you made the Flag field static, each Application Domain would still have its own independent copy and changes made by one application would not be persisted to the other.
However, if you don't mind making class1 into a singleton and are not too bothered about performance, then you can simply save the Flag field to a disk file each time you change it.
// library
// application 1
// application 2
If you start application 1 and then (from a different console window but from the same directory) you start application 2, then the former should print "false" and the latter "true" to the console.
Notice that not only will the Flag value be persisted between applications but between different runnings of those applications unless you do something to delete the text file between sessions.
Areeb QuaziPosted Jan 24, 2013, 1:56 AM
VulpesPosted Jan 23, 2013, 12:08 PM