Click here to Skip to main content
15,885,435 members
Home / Discussions / C#
   

C#

 
AnswerRe: Help on Key Press Event Pin
Calla4-Nov-09 21:47
Calla4-Nov-09 21:47 
QuestionWIA initialize object problem PinPopular
Gindi Bar Yahav4-Nov-09 11:08
Gindi Bar Yahav4-Nov-09 11:08 
AnswerRe: WIA initialize object problem Pin
Erik Rude11-Jul-10 22:11
Erik Rude11-Jul-10 22:11 
GeneralRe: WIA initialize object problem Pin
hazem00120-Jul-10 7:51
hazem00120-Jul-10 7:51 
GeneralRe: WIA initialize object problem Pin
NEspinosa23-Sep-10 14:38
NEspinosa23-Sep-10 14:38 
Questiondatetime Pin
jashimu4-Nov-09 10:15
jashimu4-Nov-09 10:15 
AnswerRe: datetime Pin
Christian Graus4-Nov-09 11:33
protectorChristian Graus4-Nov-09 11:33 
Questionneed help with adding a worker thread to my singleton Pin
abiemann4-Nov-09 9:09
abiemann4-Nov-09 9:09 
purpose
I am implementing a singleton "message queue". Several threads will enqueue messages to this queue and the worker thread will dequeue messages and process the message.

problem
in the line: "instance.threadWorker = new Thread(new ThreadStart(MessageWorker));" causes the error...
"An object reference is required for the non-static field, method, or property 'Application_Messaging.class_MessageQueue.MessageWorker()'"


code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

#pragma warning disable 0628 //suppress "new protected member declared in sealed class"

namespace Application_Messaging
{
    //singleton class because we only want one message queue
    // note: A sealed class cannot be inherited
    public sealed class class_MessageQueue
    {

        private static class_MessageQueue instance = null;
        private static readonly object padlock = new object();
        private Thread threadWorker;

        //this is a singleton, only the Instance property may be used
        protected class_MessageQueue()
        {
        }

        //property to get an instance to the class
        public static class_MessageQueue Instance
        {
            get
            {
                lock (padlock)
                {
                    if (instance==null)
                    {
                        instance = new class_MessageQueue();

                        instance.threadWorker = new Thread(new ThreadStart(MessageWorker));
                        instance.threadWorker.Start();
                    }
                    return instance;
                }
            }
        }

        private void MessageWorker()
        {
            //will be a loop to dequeue messages
        }


    }//end of: class class_MessageQueue

}//end of: namespace



how can I get the worker thread running ?
AnswerRe: need help with adding a worker thread to my singleton Pin
PIEBALDconsult4-Nov-09 9:13
mvePIEBALDconsult4-Nov-09 9:13 
GeneralRe: need help with adding a worker thread to my singleton Pin
abiemann4-Nov-09 12:51
abiemann4-Nov-09 12:51 
GeneralRe: need help with adding a worker thread to my singleton Pin
PIEBALDconsult4-Nov-09 14:05
mvePIEBALDconsult4-Nov-09 14:05 
AnswerRe: need help with adding a worker thread to my singleton Pin
Luc Pattyn4-Nov-09 9:39
sitebuilderLuc Pattyn4-Nov-09 9:39 
GeneralRe: need help with adding a worker thread to my singleton Pin
PIEBALDconsult4-Nov-09 10:56
mvePIEBALDconsult4-Nov-09 10:56 
GeneralRe: need help with adding a worker thread to my singleton Pin
Luc Pattyn4-Nov-09 11:08
sitebuilderLuc Pattyn4-Nov-09 11:08 
GeneralRe: need help with adding a worker thread to my singleton Pin
abiemann4-Nov-09 12:42
abiemann4-Nov-09 12:42 
GeneralRe: need help with adding a worker thread to my singleton Pin
Luc Pattyn4-Nov-09 12:47
sitebuilderLuc Pattyn4-Nov-09 12:47 
GeneralRe: need help with adding a worker thread to my singleton Pin
PIEBALDconsult4-Nov-09 14:22
mvePIEBALDconsult4-Nov-09 14:22 
QuestionTrouble understanding IDisposable Pin
daviiie4-Nov-09 5:35
daviiie4-Nov-09 5:35 
AnswerRe: Trouble understanding IDisposable Pin
Giorgi Dalakishvili4-Nov-09 5:44
mentorGiorgi Dalakishvili4-Nov-09 5:44 
AnswerRe: Trouble understanding IDisposable Pin
Bassam Saoud4-Nov-09 6:29
Bassam Saoud4-Nov-09 6:29 
AnswerRe: Trouble understanding IDisposable Pin
PIEBALDconsult4-Nov-09 7:46
mvePIEBALDconsult4-Nov-09 7:46 
QuestionXml Pin
md_refay4-Nov-09 4:17
md_refay4-Nov-09 4:17 
AnswerRe: Xml Pin
Not Active4-Nov-09 7:15
mentorNot Active4-Nov-09 7:15 
GeneralRe: Xml Pin
Abhishek Sur4-Nov-09 8:39
professionalAbhishek Sur4-Nov-09 8:39 
AnswerRe: Xml Pin
Abhishek Sur4-Nov-09 8:40
professionalAbhishek Sur4-Nov-09 8:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.