Re: New to C# - Please help
Thread moved from the 'CodeBank C#' forum (which is for you to post working code examples, not questions) to the 'C#' forum
Re: New to C# - Please help
Didn't realize I posted in the CodeBank. Sorry bout that.
Re: New to C# - Please help
I create threads all the time on non-static functions.
What's the code you're using to create the thread?
Re: New to C# - Please help
Hi, thanks for the reply.
Code:
namespace NiRDs
{
public partial class frmMain : Form
{
#region Public Declarations
public Thread t_StartNiRds = new Thread(StartNiRds);
}
}
Then I have the declaration of the StartNiRds function.
Code:
public static void StartNiRds()
{
}
If I remove the static from the StartNiRds function I get this error.
A field initializer cannot reference the non-static field, method, or property 'NiRDs.frmMain.StartNiRds()'
Re: New to C# - Please help
Ah - try making it equal to null and then in the Form Initialize, you can create the "new Thread" part.
I usually also use a Thread Start, so the whole thing looks like this:
Code:
//In global space:
System.Threading.Thread WorkMule = null;
//In the constructor, after Initialize Component:
WorkMule = new System.Threading.Thread(new System.Threading.ThreadStart(DoWork));
//When I want to start it:
WorkMule.Start();
//The declaration of the DoWork class:
void DoWork()
{ //My code }
Re: New to C# - Please help
Oh, thanks very much. I had a large application coded in VB and I'm porting it to C# so I never had these problems. LoL.
What is the purpose of the ThreadStart?
Re: New to C# - Please help
I don't think you have to do it anymore, but I have been programming from when .Net was still "preview candidate" and it was needed then, so I got used to using it.
I think now, the compiler simply does it for you if you don't.
If I'm wrong about the compiler, then its purpose is to store the delegate address (aka "where your function is at in memory") so that you can later call "Start" on it.
Re: New to C# - Please help
Oh ok, I see now. Most likely the compiler does do it for you because in VB I don't have to declare it that way but it makes perfect sense.
Thanks again!
Re: New to C# - Please help
Actually, maybe you can help me with one more thing.
I'm getting this error for some reason....
"Operator '|' cannot be applied to operands of type 'WindowsService.ACCESS_MASK' and 'int' "
Code:
private const Int32 SC_MANAGER_QUERY_LOCK_STATUS = 0x00010;
private const Int32 SC_MANAGER_CONNECT = 0x00001;
private const Int32 SC_MANAGER_CREATE_SERVICE = 0x00002;
private const Int32 SC_MANAGER_ENUMERATE_SERVICE = 0x00004;
private const Int32 SC_MANAGER_LOCK = 0x00008;
private const Int32 SC_MANAGER_MODIFY_BOOT_CONFIG = 0x00020;
private const Int32 SC_MANAGER_ALL_ACCESS = ACCESS_MASK.STANDARD_RIGHTS_REQUIRED | SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_LOCK | SC_MANAGER_QUERY_LOCK_STATUS | SC_MANAGER_MODIFY_BOOT_CONFIG;
Code:
[Flags()]
private enum ACCESS_MASK : uint
{
DELETE = 0x10000,
READ_CONTROL = 0x20000,
WRITE_DAC = 0x40000,
WRITE_OWNER = 0x80000,
SYNCHRONIZE = 0x100000,
STANDARD_RIGHTS_REQUIRED = 0xf0000,
STANDARD_RIGHTS_READ = 0x20000,
STANDARD_RIGHTS_WRITE = 0x20000,
STANDARD_RIGHTS_EXECUTE = 0x20000,
STANDARD_RIGHTS_ALL = 0x1f0000,
SPECIFIC_RIGHTS_ALL = 0xffff,
ACCESS_SYSTEM_SECURITY = 0x1000000,
MAXIMUM_ALLOWED = 0x2000000,
GENERIC_READ = 0x80000000,
GENERIC_WRITE = 0x40000000,
GENERIC_EXECUTE = 0x20000000,
GENERIC_ALL = 0x10000000,
DESKTOP_READOBJECTS = 0x1,
DESKTOP_CREATEWINDOW = 0x2,
DESKTOP_CREATEMENU = 0x4,
DESKTOP_HOOKCONTROL = 0x8,
DESKTOP_JOURNALRECORD = 0x10,
DESKTOP_JOURNALPLAYBACK = 0x20,
DESKTOP_ENUMERATE = 0x40,
DESKTOP_WRITEOBJECTS = 0x80,
DESKTOP_SWITCHDESKTOP = 0x100,
WINSTA_ENUMDESKTOPS = 0x1,
WINSTA_READATTRIBUTES = 0x2,
WINSTA_ACCESSCLIPBOARD = 0x4,
WINSTA_CREATEDESKTOP = 0x8,
WINSTA_WRITEATTRIBUTES = 0x10,
WINSTA_ACCESSGLOBALATOMS = 0x20,
WINSTA_EXITWINDOWS = 0x40,
WINSTA_ENUMERATE = 0x100,
WINSTA_READSCREEN = 0x200,
WINSTA_ALL_ACCESS = 0x37f
}
If I remove the ACCESS_MASK.STANDARD_RIGHTS_REQUIRED, the error goes away. Why is this occuring?
Re: New to C# - Please help
Quote:
Originally Posted by
taigon
If I remove the ACCESS_MASK.STANDARD_RIGHTS_REQUIRED, the error goes away. Why is this occuring?
Are they they same data type?
Re: New to C# - Please help
Actually, I figured this one out. Thanks for your help.