By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,566 Members | 1,774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,566 IT Pros & Developers. It's quick & easy.

Thread Ssuspend / CPU Usage 100%

P: n/a
I have a static ServiceFactory. After suspending the thread, the CPU is using 100% CPU. There is no way in debugging this error. Could you give me a hint?
Code:

using System;
using System.Threading;

namespace XY
{

public class ServicesFactory
{
private static Playerlist playerlist;
private static CardDeck cardDeck;
private static Scoreboard scoreboard;
private static RowMaster rowMaster;
private static Dealer dealer;
private static RemoteEntryPoint remoteEntryPoint;
private static Thread mainThread;

private ServicesFactory(){}

/// <summary>
/// Property Dealer
/// </summary>
public static Dealer Dealer
{
get
{
if(dealer == null)
dealer = new Dealer();

return dealer;
}
}
/// <summary>
/// Property RowMaster
/// </summary>
public static RowMaster RowMaster
{
get
{
if(rowMaster == null)
rowMaster = new RowMaster();

return rowMaster;
}
}


public static void HostRun()
{
Console.WriteLine(">>> HOST:HostRun.");
if(mainThread == null)
mainThread = Thread.CurrentThread;

if(mainThread.ThreadState == ThreadState.Suspended)
{
mainThread.Resume();
Console.WriteLine(">>> HOST WURDE FORTGESETZT (resume).");
}
}
public static void HostWait()
{
Console.WriteLine(">>> HOST:HostWait.");
if(mainThread == null)
mainThread = Thread.CurrentThread;

Console.WriteLine(">>> HOST WURDE ANGEHALTEN (suspend).");
mainThread.Suspend();
}

}
}

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>xXZzcH8YU0m3DDuEGCm+1A==</Id>
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I'm confused - without seeing the driving code I'm not sure how this works. HostRun seems like its broken

It stores the current thread then checks to see if its suspended, if it is it resumes it. Obviously HostRun will not execute if the current thread is suspended. So I can only guess that HostRun or HostWait are called to "prime" the mainThread member.

You need to supply more info so we can try to diagnose the problem

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I have a static ServiceFactory. After suspending the thread, the CPU is using 100% CPU. There is no way in debugging this error. Could you give me a hint?
Code:

using System;
using System.Threading;

namespace XY
{

public class ServicesFactory
{
private static Playerlist playerlist;
private static CardDeck cardDeck;
private static Scoreboard scoreboard;
private static RowMaster rowMaster;
private static Dealer dealer;
private static RemoteEntryPoint remoteEntryPoint;
private static Thread mainThread;

private ServicesFactory(){}

/// <summary>
/// Property Dealer
/// </summary>
public static Dealer Dealer
{
get
{
if(dealer == null)
dealer = new Dealer();

return dealer;
}
}
/// <summary>
/// Property RowMaster
/// </summary>
public static RowMaster RowMaster
{
get
{
if(rowMaster == null)
rowMaster = new RowMaster();

return rowMaster;
}
}


public static void HostRun()
{
Console.WriteLine(">>> HOST:HostRun.");
if(mainThread == null)
mainThread = Thread.CurrentThread;

if(mainThread.ThreadState == ThreadState.Suspended)
{
mainThread.Resume();
Console.WriteLine(">>> HOST WURDE FORTGESETZT (resume).");
}
}
public static void HostWait()
{
Console.WriteLine(">>> HOST:HostWait.");
if(mainThread == null)
mainThread = Thread.CurrentThread;

Console.WriteLine(">>> HOST WURDE ANGEHALTEN (suspend).");
mainThread.Suspend();
}

}
}

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.