Question: So, around a week ago I asked a question about activex and UDP. Here it is:

[C# UDP Socket client and server](https://stackoverflow.com/questions/19786668/c-sharp-udp-socket-client-and-server)

Now, I created two applications, one (the sender) to send pre-defined strings via UDP. The other is activex component that is called from a webpage, and it's thread is working in the background. Once an UDP message arrives, then it's doing it's stuff (writing in database, writing in log.txt, and so on). 

The last thing i need is to return data (it's yet to be said if it will be string or something else). However, the method in the activex which is called must be a void, because if it's made to be string, the threading wont work, and only the first message will arrive.

My question is, how to do that? How to return data from a void function? For example, the web app now is calling the activex DLL like this:

```
    ClassLibrary1.Class1 activex = new ClassLibrary1.Class1();
    activex.StartThread();

```

And the StartThread() calls the listening thread and it's working in the background, and once UDP msg arrives, its doing some stuff like i said above.

How can i return value with the threads (events) and the web app will catch it and use it?

Thanks a lot.

Answer: 
Basically you have to store some data in a spot where you can access it from both places (from the thread, and from the place where you started the thread). So you have a couple of options from the top of my head.

1. Store it in a database
2. Create a specific object (whatever type you need), and store it in a place where it is accessible from both places. For example, a singleton. A simpler better solution is to create a property on your ClassLibrary.Class1 class: set it from within the Class1-class, and get it from the place where you created an instance of your Class1-class.
3. Add an event to your Class1-class which fires when it is finished doing its job. And add some data to the EventArgs.

I'm assuming here you get notified when your thread is done doing whatever it is doing.

Edit: added events
The threading function can change the fields values of the class and you can access those fields, also your thread can fire events that other classes can subcribe to and then act on it.

```
Class1
{
 private string value;
 public string Value{get{return value;} set{value=value; FireTheEvent();}}
}

```