|
HI,
I create some thread and i want to stop one of them.
I don't want to use Abort method.
Is there is some other way to terminate the tread ?
|
|
|
|
|
The best way is to tell the thread to stop itself. Put a volatile boolean varable in the class for the thread. Make the thread check the value of the boolean regularly, so that it can exit when the value changes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Let take For Example :
private void OnClockStart()
{
while (ClockTick)
{
this.Invoke(clockHandler);
Thread.Sleep(1000);
}
clockThread.Abort();
}
ClockTick = Bool To Check & When u Want to Stop The Thread You Just Assgin False
the While Will break and The clockThread.Abort(); Method will Execute
Have Fun
Never forget it
|
|
|
|
|
I think in your example, clockThread.Abort(); is not needed as making "clockTick" false will end the method which will stop the thread. So no need to abort it explicitly.
|
|
|
|
|
You can use a volatile boolean variable, if it is set as false, exit the method. This is the safest way for cancellation. You can call Thread.CurrentThread.Abort() also, aborting from a known location is safe.
|
|
|
|
|
Rather than a boolean, I suggest looking at a ManualResetEvent(). Threads are often in wait states and this allows you to avoid a polling model.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
i am creating a shortcut for google using IWshRuntimeLibrary. My code is like this
shortcut1 = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@"C:\Google.lnk");
shortcut1.TargetPath = "http://www.google.com";
shortcut1.Description = "Open Google";
shortcut1.IconLocation = "C:\\icon.ico";
it works quite good.
The problem that i have is when i copy it to another system the icon image is not displayed. I know the problem is
shortcut1.IconLocation = "C:\\icon.ico";
where i specify the icon path on the other system it does not exist. One solution is to copy the icon in C drive but i don't need this.
What i need is this there should be no need to copy icon.
Is there any way to do this that i dont have to copy icon just copy the shortcut.
One possibility is to use windows icons but i want to use my own image(icon).
|
|
|
|
|
A shortcut file can not contain an icon, so you have to have it in a separate file. You have to copy the icon file along with the shortcut.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I have some text box ( multi line ) and i need to add 4 lines.
I want to add them in some way that the structure will be same - i mean like this
Somestr123 info1
Somestr456789 info2
.
.
.
So, I want to format each line in some way that i could have same structure.
I know the maximum string Length of each string.
Thanks.
modified on Sunday, June 22, 2008 5:11 AM
|
|
|
|
|
Use tabs '\t' or fill the gaps with spaces and use a monospace font like Lucida Console or Courier New
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks,
But i need to format the string in different way.
The '\t' give me 4 spaces only and cant help me to save the same format.
I looking for some format that can save me the state of the line.
|
|
|
|
|
Spaces + Monospace Font, as I said.
This of course depends on the font the viewer of the data uses, but there's no other way than to use the same string length via spaces and then force the viewer program to use a monospace font.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
a ListBox is more suited to show independent lines of text:
- it never needs the concatenation of all text lines
- it knows how to store a collection of objects, not just strings
- it allows for user drawing.
Without user drawing, you would have to choose a non-proportional (=monospace) font
and insert spaces and/or tabs to align columns.
With user drawing (set DrawMode to DrawMode.OwnerDrawFixed), you can draw each line
yourself. If you have stored a small struct (say string col1, string col2), you can
now paint the different columns individually, using whatever color, size, etc you choose.
|
|
|
|
|
Hi.
I'm trying to connect to SQL Server Express using a DSN. The DSN and SSE is set up with Windows NT authentication. I've tried SqlConnection thisConnection = new SqlConnection("DSN=ESGAS;Integrated Security=SSPI;"); but I get an error saying 'dsn' is not a recognised keyword.
Thanks in advance.
The FoZ
|
|
|
|
|
Don't worry I think I've solved it. It seems that the SqlConnection uses its own protocol to connect to the SQL Server as per this[^] article on MSDN.
The FoZ
|
|
|
|
|
Hi,
I'm using a outlook 2007 add-in project. In this project I added a reference to a dll. Somehow I can't make any calls to any of the methods in that dll. I keep getting FileLoadException. I have strong named this assembly. I read in one place that I have to grant trust to that assembly. Any idea how to fix this? After adding strong name I get this error:
A first chance exception of type 'System.IO.FileLoadException' occurred in MyClass.DLL
Could not load file or assembly 'MyClass, Version=1.0.3094.41526, Culture=neutral, PublicKeyToken=52388ff89a43b4bd' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)
Thanks
Ben
|
|
|
|
|
Hi All,
I've not used reflection before so this is all really new to me. I have an object that I want to build in some automating dynamic behaviour based on what 'called it'. What's the best way to get the Type name of the calling type in this objects constructor?
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
You could pass it to the constructor for the new object and then use the System.Object.GetType() method to get it's type (of the object that constructed it) and do further processing from there.
There's a bunch of different ways. And it depends on how many "calling" objects you're dealing with.
|
|
|
|
|
Thanks Bert,
It does make more sense to pass it in and then build some form of switch statement I guess.
Thanks,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
You can look at the collection of StackFrame objects returned by System.Diagnostics.StackTrace. The first frame should be your constructor, and the second the method that called it.
|
|
|
|
|
Ahhhhh!! Thanks chap!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Unfortunately this does not work in all cases and is not guaranteed to work in future versions of the framework. See Mike Stall's blog [^]for more info.
The question one should be asking is "why does the constructor need to know the declaring type of its calling method?"
|
|
|
|
|
Thanks, I didn't know that. Ya, if the question is unavoidable, I suppose passing the result of this.GetType() to the constructor is nice and clear about what is going on.
|
|
|
|
|
Hi everybody.
Is it allowed to mix lock and Monitor.TryEnter commands on the same locking object? I think that lock is implemented using Monitor.Enter and Monitor.Exit - so there should be no problems. Am I correct?
Thanks
Uros
|
|
|
|
|
Yes, lock is expanded by the compiler to Monitor.Enter /Monitor.Exit , so
lock (obj)
{
} gets expanded to
Monitor.Enter(obj);
try
{
}
finally
{
Monitor.Exit(obj);
} I'm not sure how you would mix the Monitor.TryEnter with using a lock on the same object since you would then be acquiring two locks on the same object.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines][ Articles][ Blog]
|
|
|
|