Async activities from class not derived from Control

  • Thread starter Thread starter Valerie Hough
  • Start date Start date
V

Valerie Hough

I want to create a utility class which is defined as follows:

public Class MyDataReadingClass
{
....
}

In that class I want to encapsulate all the logic for performing certain SQL
Server queries and have the result set accessible from my parent, which will
always be a System.Windows.Form object.

My problem is that since my class is not derived from Control, I do not have
access to Invoke() in my async callback handler, where I would normally pass
my SqlDataReader via Invoke to a safe place from which its contents can be
accessed without synchroniziation issues.

It seems silly to be deriving my utility class from Control when it is not
really a control, but I want to be able to create instances of my data
reading utility class in different places in my applications.

Can someone please help?

Thanks in advance.

Valerie Hough
 
Valerie Hough said:
[...]
My problem is that since my class is not derived from Control, I do not
have
access to Invoke() in my async callback handler, where I would normally
pass
my SqlDataReader via Invoke to a safe place from which its contents can be
accessed without synchroniziation issues.

Why not just the usual thread synchronization mechanisms? A mutex seems
like it would be a suitable solution. Is there something about your
implementation that precludes using one?

IMHO, Invoke isn't a great solution anyway. It solves a very specific need,
where the OS has specifically required certain things happen on a certain
thread. But it sounds like in your case all you really want is to prevent
multiple threads from accessing the same data at the same time. That's a
great job for a mutex (or any of the similar mechanisms).

Pete
 
Back
Top