|
ke5in wrote:
Q1: Is encapsulating the thread in the class like this bad practice?
No. It looks reasonable enough.
ke5in wrote:
Assuming that there is nothing wrong with encapsulating the thread, is there anyway I can terminate it in a destructor? I would like to see this thread die when the instance of the class goes out of scope. I think explicitly calling the kill method is lame. (Or do I just have to get used to the way things are destroyed in C#?)
Since GC is non-deterministic in .NET you could never be sure when the destructor of your class is run. If you don't mind the thread hanging around for some time after the class goes out of scope you could put the kill() call in the destructor. Although i wouldn't advise it.
May the Source be with you
Sonork ID 100.9997 sijinjoseph
|
|
|
|
|
My answer would be to implement events in the threaded class (Started and Exit) and responding to them in the main program.
The library I use for my IRC client makes use of threaded classes like this (i think, as far as i can see anyways )
Have a look at http://thresher.sourceforge.net[^]
The library runs rock solid, so I would assume this is the correct way to do it.
Hope this Helps
PS: ke5in, plz dont tick respond when receiving a reply, if you dont have a working email address ( or fix tour email address). Err: To: "ke5in" <temp1@appliedmobile.com> Mail returned - user not found.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
ke5in wrote:
Q1: Is encapsulating the thread in the class like this bad practice?
Not particularly, but why not have a seperate class containing an event, replace the ManualRaiseEvent with this class and then have an event handler in your Worker class?
I tend to believe in threading when I want two things to happen simultaneously (maybe if your Worker thread was continuously updating a database or an on-screen display while the program was off doing something else) rather than just waiting for something to happen. That's what events are for.
ke5in wrote:
Q2: Assuming that there is nothing wrong with encapsulating the thread, is there anyway I can terminate it in a destructor? I would like to see this thread die when the instance of the class goes out of scope. I think explicitly calling the kill method is lame. (Or do I just have to get used to the way things are destroyed in C#?)
Nothing wrong with doing it this way... you might want to call it "Dispose" though, that's the C#/VB.NET standard for killing something without waiting for it to be deconstructed.
ke5in wrote:
Q3: What is the “approved” method of waiting for a thread to start?
i.e. is there anything better than this:
while(t.ThreadState == ThreadState.Unstarted){}
Seems like a good method to me. You might want to Sleep(10) in the loop though, just so other programs can get at your processor while you're waiting.
Paul
|
|
|
|
|
I see a LOT of people are looking at remoting recently. Ive taken a look and it seems that creating a tcp channel and registering it is the way msft want you to talk between two applications.. even on the same machine.
Isnt that a huge security issue? I have to make a powerbuilder app communicate with a C# app. I dont want to put COM in the C# part of the application and I DEFINITELY dont want to deal with registering objects... ever again.
How can I get these two apps to communicate without having a registered COM object AND do it securely?
|
|
|
|
|
poodull wrote:
I dont want to put COM in the C#
Use remoting to avoid COM, and why don't you think security exist in remoting?
Soliant | email
"The whole of science is nothing more than a refinement of everyday thinking." -Albert E.
|
|
|
|
|
How I get the feel of a Wizard dialog in C#/Windows Forms?
I would like to make dialogs that acts like wizards.
Now I am using a buggy procedure of overlapped panels, that I hide and unhide.
What is the proper way to do that?
THX
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
|
|
I think its time for regular expressions HAHAHHAHA evil laugh from Dr. Evil
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
I did something like this in ASP, however it does allow some HTML tags:
Function CleanHTML(html)
Dim re
Set re = New RegExp
re.Global = true
re.IgnoreCase = true
re.Pattern = "[<][<body *>|</body>|<input*>][^<br>][^<b>][^</b>][^<i>][^</i>][^>]*[>]"
CleanHTML = re.Replace(html,"")
Set re = Nothing
End Function
You can fit it to your liking. HTH
Nick Parker
|
|
|
|
|
Does anyone know if there is a problem with using an interface type as the type in the XmlSerializer constructor?
|
|
|
|
|
I doubt it will work... considering that interfaces don't include constructors, and the xmlserializer requires one.
|
|
|
|
|
|
XmlSerializer will not allow typeof(IMyInterface) as its reflected type. Its understandable as XmlSerializer does not use properties but only actual members. I guess this makes sense under the presumption of using get/set value members as interpreted values (ie they are generated from some other value in the class). Uhoh - they expect me to be logical... whats that crap about.
ie
private int mynumber; //serialized
private int myothernumber { //not serialized
get { return mynumber; }
set { mynumber = value; }
}
|
|
|
|
|
Cromwell wrote:
private int mynumber; //serialized
private int myothernumber { //not serialized
get { return mynumber; }
set { mynumber = value; }
}
What the point of a private property, if it is not used? Sure , internal, protected and public have there reason, but I cannot see the purpose of a private property.
Just my 2 cents
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
I cannot see the purpose of a private property.
I would use them to wrap other operations that need to be performed when setting the value. Pretty much the same reason you would use any property in the first place
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
leppie wrote:
What the point of a private property, if it is not used? Sure , internal, protected and public have there reason, but I cannot see the purpose of a private property.
1) I was just showing that because an interface cannot define actual member variables only methods, it makes sense that you cannot use them for XmlSerializer.
2) Oh my lordy - really! Private properties are sooo useful. Often over used by lazy (vb6 uhum :P - no offense just hate it) developers, but none-the-less important.
|
|
|
|
|
Hi all,
When you need to pass a struct to an unmanaged function, does the variables need to made public or can they be set otherwise and be accessible only thru there properties.
EG (what i normally do)
public struct Point
{
public int x;
public int y;
}
Can I do?
public struct Point
{
int x;
int y;
public int X {get;set;}
public int Y {get;set;}
}
Will the unmanaged function still function as normal?
Thanx all
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Pretty stupid question I guess.
What would the unmanaged function anyways know about public/private/etc...
This makes life so much more interesting
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I've created a second windows form in my project, which is a simple dialog which I want to use for 'search and replace' in my text fields. It has a couple of text fields and a few buttons, all created via the wizards. When I create an instance of my dialog, it crashes in the line:
this.ResumeLayout(false);
with a NullReferenceException. I don't see why - I create the dialog using new, and it all seems kosher to me. Does anyone have any suggestions ?
public SearchDialog(bool bReplace, string sText)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
m_sText = sText;
m_bReplace = bReplace;
if (!bReplace)
{
Replace.Enabled = false;
All.Enabled = false;
}
//
// TODO: Add any constructor code after InitializeComponent call
//
}
SearchDialog sd = new SearchDialog(false, m_XMLObject.GetXML());
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
I don't see why that line would cause it to crash, since the code is executed within a non-static constructor the this reference has to exist
Have you installed SP2?
If you haven't, it might actually be crashing on the previous line; but due to a bug (fixed in SP2) it shows the wrong line.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
James T. Johnson wrote:
If you haven't, it might actually be crashing on the previous line; but due to a bug (fixed in SP2) it shows the wrong line.
That was a bug and i thought that was normal.
May the Source be with you
Sonork ID 100.9997 sijinjoseph
|
|
|
|
|
No, I haven't. The previous line was one that took an array of controls, all of which have had 'new' called on them, and when I comment it out, it still crashes. Basically the Winforms wizards are crap, is my conclusion, as every bit of the code in question was generated by the wizard and none of it was complex.
I gave up in the end, deleted the dialog and did it on the main form.
Thanks for the advice, I'll get SP2 ASAP.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Christian Graus wrote:
Winforms wizards are cra
Yes they are
I just hate getting all that InitializeComponent() junk, plus some random cleanup function I forget the name of. The code is rather inefficient and ugly too! (No tab alignments).
I just use Windows Forms to calculate coordinates then do it myself.
-Domenic Denicola- [CPUA 0x1337]
MadHamster Creations
"I was born human. But this was an accident of fate - a condition merely of time and place. I believe it's something we have the power to change..."
|
|
|
|