Click here to Skip to main content
15,892,005 members
Home / Discussions / C#
   

C#

 
QuestionWhere is my memory? [modified] Pin
lak-b9-Apr-07 5:17
lak-b9-Apr-07 5:17 
AnswerRe: Where is my memory? Pin
S. Senthil Kumar9-Apr-07 6:36
S. Senthil Kumar9-Apr-07 6:36 
GeneralRe: Where is my memory? Pin
lak-b9-Apr-07 7:49
lak-b9-Apr-07 7:49 
GeneralRe: Where is my memory? Pin
S. Senthil Kumar9-Apr-07 9:28
S. Senthil Kumar9-Apr-07 9:28 
QuestionDecorator Pattern Related Question Pin
jubilanttiger9-Apr-07 4:31
jubilanttiger9-Apr-07 4:31 
AnswerRe: Decorator Pattern Related Question Pin
Leslie Sanford9-Apr-07 6:14
Leslie Sanford9-Apr-07 6:14 
QuestionThread Aorting Pin
HexaDeveloper9-Apr-07 3:37
HexaDeveloper9-Apr-07 3:37 
AnswerRe: Thread Aorting Pin
Leslie Sanford9-Apr-07 5:32
Leslie Sanford9-Apr-07 5:32 
HexaDeveloper wrote:
i tried to abort thread but when i make
myThread.Abort();
it give me an exception of aborting thread so what can i do to avoid this exception


Allow the thread to end naturally. Typically, a thread method has a loop that it runs until it completes its task.

private void ThreadMethod
{
    while(notDone)
    {
        // Do stuff here...
    }
}


HexaDeveloper wrote:
another thing is that Suspend Method is obsolete(help said)
what is the alternative


Hmm, well you could use locking to pause a thread:

private void ThreadMethod
{
    lock(lockObject)
    {
        Monitor.Wait(lockObject);
    }
 
    while(!done)
    {
        // Do stuff here...
    }       
}


And at the point in which you create the thread:

Thread myThread = new Thread(ThreadMethod);
 
myThread.Start();
 
lock(lockObject)
{
    Monitor.Pulse(lockObject);
}


This will create a thread and start it. The thread runs until it reaches the Monitor.Wait(lockObject) statement. At that point, it's up to you to wake up the thread and let it do its thing. This is done above with the Monitor.Pulse(lockObject) statement.

Now, often times you want a thread to wait periodically instead of just when it's started up. So we can put a Wait inside the loop:

private void ThreadMethod
{
    lock(lockObject)
    { 
        while(!done)
        {
            Monitor.Wait(lockObject);
 
            if(done)
            {
                break;
            }
 
            // Do stuff here...
        }       
    }
}


Then it's up to your application to periodically wake up the thread to do its work. Hope this helps.

HexaDeveloper wrote:
third and last:
when i declare thread as member data in class it refuses to identify the name of the method i used to initialize
like:


This question I don't understand. Can you elaborate?
GeneralRe: Thread Aorting [modified] Pin
HexaDeveloper10-Apr-07 14:01
HexaDeveloper10-Apr-07 14:01 
Questioncombobox database value Pin
msogun9-Apr-07 3:36
msogun9-Apr-07 3:36 
AnswerRe: combobox database value Pin
Colin Angus Mackay9-Apr-07 3:42
Colin Angus Mackay9-Apr-07 3:42 
QuestionWhich is better C# or VC++.NET Pin
BlrBoy9-Apr-07 2:33
BlrBoy9-Apr-07 2:33 
AnswerRe: Which is better C# or VC++.NET Pin
Colin Angus Mackay9-Apr-07 3:41
Colin Angus Mackay9-Apr-07 3:41 
QuestionBetter to save locally? Pin
Aaron VanWieren9-Apr-07 2:27
Aaron VanWieren9-Apr-07 2:27 
AnswerRe: Better to save locally? Pin
Colin Angus Mackay9-Apr-07 3:40
Colin Angus Mackay9-Apr-07 3:40 
GeneralRe: Better to save locally? Pin
Aaron VanWieren9-Apr-07 5:47
Aaron VanWieren9-Apr-07 5:47 
GeneralRe: Better to save locally? Pin
Colin Angus Mackay9-Apr-07 6:22
Colin Angus Mackay9-Apr-07 6:22 
GeneralRe: Better to save locally? Pin
Aaron VanWieren9-Apr-07 6:33
Aaron VanWieren9-Apr-07 6:33 
QuestionHow to invoke web service method in C#.Net Pin
shanthivasan9-Apr-07 2:25
shanthivasan9-Apr-07 2:25 
AnswerRe: How to invoke web service method in C#.Net Pin
WillemM9-Apr-07 7:01
WillemM9-Apr-07 7:01 
QuestionReport Viewer Pin
vinayak baddi9-Apr-07 2:07
vinayak baddi9-Apr-07 2:07 
QuestionHow to create Poker Game!!! Pin
DukeKing9-Apr-07 1:41
DukeKing9-Apr-07 1:41 
AnswerRe: How to create Poker Game!!! Pin
Colin Angus Mackay9-Apr-07 1:50
Colin Angus Mackay9-Apr-07 1:50 
GeneralRe: How to create Poker Game!!! Pin
Leslie Sanford9-Apr-07 5:35
Leslie Sanford9-Apr-07 5:35 
GeneralRe: How to create Poker Game!!! Pin
Dan Neely9-Apr-07 5:48
Dan Neely9-Apr-07 5:48 

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.