?
Solved

How do I create make a series of Queue's accessible to multiple classes?

Posted on 2006-11-01
2
Medium Priority
?
152 Views
Last Modified: 2010-04-16
Hi,

How do I create make a series of Queue's accessible to multiple classes?

I.e.

1. One part of the application has data fed in;

2. The application stores this information into a Queue;

3. This Queue just keeps on building with new data - lets say *a lot* of data is being added every second.

4. (Stuck on this) I have classes with code ready to manipulate this data and send it to a DB (store it) and a management application (do-something) via SqlConnection and TCP respectively.

I intend:

Several threads will be "active" using these classes, each using `aString = aQueue.Dequeue()`, and then manipulating aString before sending it off over the wire. Taking the data from the Queue obviously stops other threads getting it.

Multiple threads will be used to try and ensure the queue is always as empty as possible. Going across a network will take at least a few MS, which obviously is not going to be burning processing time... that can instead be used to manipulate the next item.

For this method to work, all threads need to use a centralised "store" - the Queue(s) - and strip off one piece of work at a time (thus Dequeue).

So what you will have happening is data being added to queues from a.disperate.source, and then several threads looking at this queue to pull the information apart… continuously.

So.. The question is: **How** do I make it so these Queues can be accessed by the thread adding data in, and also the threads taking data out?

Any input gratefully received..!

Cheers

**Note: **

Error when trying public static:
cannot declare instance members in a static class

Error when using public:
An object reference is required for the nonstatic field, method, or property
( Can an instance of the class be made, and then accessed by everything else… data adder class + handler classes and the threaded instances of them? If so... how?)
0
Comment
Question by:James_15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 17854232
Declare a static member in a normal class like this:

    public class DataStore
    {
        public static Queue aQueue = new Queue();
    }

    public partial class Form1 : Form
    {

        private void button1_Click(object sender, EventArgs e)
        {
            DataStore.aQueue.Enqueue("a");
            DataStore.aQueue.Enqueue("b");
            DataStore.aQueue.Enqueue("c");

            while (DataStore.aQueue.Count > 0) {
                System.Diagnostics.Debug.Print((string)DataStore.aQueue.Dequeue());
                Application.DoEvents();
                System.Threading.Thread.Sleep(1000);
            }
        }

    }
0
 

Author Comment

by:James_15
ID: 17876322
Perfect - cheers!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question