Thread Ssuspend / CPU Usage 100%

  • Thread starter Thread starter Mister Blister via .NET 247
  • Start date Start date
M

Mister Blister via .NET 247

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();
}

}
}
 
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();
}

}
}
 
Back
Top