Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I dont know if I have labelled the question correctly above so it will probably be more clear if I explain my issue.

What I want, is for each class to be opened and for their instances to be separate - in VB6, there was a "Apartment Threaded" tick box in the project properties, but I cannot seem to find anything similar at all in VS and I presume (and I could be wrong) that, that setting in VB6 would make each instance of that class, individual and not interfere with each instance operation.

I have a "main winforms app" that needs to call a DLL Class I have created.
The user can open up that DLL class multiple times.
There is a database connection in that DLL class. The database connection is opened and is kept opened throughout the lifetime of that class that is open and is closed when the dll class form is unloaded.

If I have 2 or more of these DLL classes running and one of them gets closed, in my closing of the DLL, the database connection is also closed - however, it closes the database connection for all of the opened DLL Classes.

What I need, is for the DLL class instance that has been created, is for it to have its own connections etc.. (that are managed in that DLL Class) to be separate to other multiple instances of that DLL class that have been called.

Does that make sense? - to simplify this an example:

I have a winforms project, one button.
I click on that button and the code is

Dim NewForm as New ABC_Class
NewForm.MyVar=Label1.Text
NewForm.DoStuff

the DLL class gets called, opens up a database connection and fetched some data depending on the properties assigned to that class from the main app.

I perform a same click on the button except in Label1.Text I have a different value so clicking on the button, calls the DLL Class, a form appears and data relevant to Label1.Text value appears - great - I now have 3 forms open (the main winforms form with the button) and two DLL Classes displaying info that was relevant at the time of being called.

The database connection remains open for both opened classes. I close one of the classes and it closes the database connection.

There is a button on the remaining open DLL class that will go and fetch something else from the database but it fails because the connection has been closed - I assume, from the original DLL class that I just closed.

If I have variables stored in the one class - is that then affected when a second copy of the class has been created, even though I have used "New" in my declaration?

Even variables are shared between two New instances of that class (I have tried it) - Im not sure where to go with this as I need that class opened up multiple times from the same button but to contain their own objects and not be shared.

I know its a very basic question but it is one that I am unable to find a solution from googling it - perhaps I am using the wrong terminology but I cannot find the words to describe what I am trying to achieve that bring back the results that I am after.

What I have tried:

Created two buttons on the main form, one declaring dim newFrm1 as New and another button with newFrm2 as another declaration, yet variables from both instances remain shared and not private to their own instance.

I have even googled "vb.net equivalent of apartment thread property vb6 project property" and I just seem to get vb6 related COM items instead of a vb.net calling a vb.net DLL.

The nearest I have seen to it, was a similar query and the solutions provided was to have separate physical file copies of the DLL to do different things - that seems ridiculous to me, surely a true separate instance of the same DLL can be created - it worked in VB6 and Im pretty sure as .net is a load better than vb6, that there will be a simple parameter or sub I need to create that would do this for me.
Posted
Updated 8-Jul-18 23:25pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900