|
Yes. It's thread safe because it releases the lock in the 'finally' block before the control flow exits the block of code. Finally blocks always get executed...
|
|
|
|
|
I have no idea how I can publish my project. (Visual Studio 2005) Who can help me with an example.
|
|
|
|
|
You mean with ClickOnce ?
|
|
|
|
|
Hello all of you!
I have a strange problem and I need help to solve it.
I have a windows application written in C# that sporadically terminates, no exceptions, no error codes, no messages at all. The application starts a new thread which sends information to the windows form via events. The thread uses USB-connected printers to print small paper-labels and a USB-CAN interface.
Is it a thread related error? Deadlock? Stack overflow?
Is it caused by a collision in the USB-interface?
Hopfully, Daniel Carlson
|
|
|
|
|
Do you wait until your Printer thread is finished before terminating your main thread ?
Regards
|
|
|
|
|
Actually, no...!?
This might be the answer to my problem. Let me describe the problem further.
Call my main-thread "A". "A" starts a new thread, "B", witch will do some work. At the end of "B" a small label will be printed using the System.Drawing.Printing.PrintDocument.Print() method. As I have got it, this standard method starts a new thread "C", a printing-thread.
I do not wait for "C" to terminated in "B", parhaps I should...
Thanks for your reply.
//Daniel
|
|
|
|
|
Hi,
Try using the Thread.Join() member which causes the calling thread to block until the thread terminates.
I do not know how your workflow works, but please see the example in
http://msdn2.microsoft.com/en-us/library/system.threading.thread.aspx
Regards
|
|
|
|
|
Hi all,
I am using threads to asynchronously work on independent forms in the following way:
Thread th = new Thread(new ThreadStart(batchViewer.InvokeBatch));
th.IsBackground = true;
th.Start();
batchViewer is a class in another namespace.
InvokeBatch is a method in batchViewer.
Now to come back to the class where thread is created i get the problem of circular dependency.
How do i CallBack when the thread is completed?
Thanks.
|
|
|
|
|
Hi,
that depends on your situation. One way would be to add an event to batchViewer which is fired when the InvokeBatch call is completed. You could than handle this event. Be aware of the fact that the event handler will be called within the context of the thread. So you'll have to use Invoke if you want to pass the call into your GUI thread.
Robert
|
|
|
|
|
Why not just use a delegate as a property of the batchViewer? Set it before starting the thread, and call back to it when InvokeBatch is finished?
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Not sure how it fits BUT I for one thank you for sharing your knowledge..
Without it I be lost at what to do for ANYTHING!
|
|
|
|
|
Nice one. Shows real class. You'll soon be answering questions for others
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi I found some code in an article posted on code project "Asynchronous Method Invocation" and was trying to follow the article, and convert it to vb.net, and got stuck at the last section of the article. I was wondering if anyone out there knows what the code below does, and how to convert it to vb.net. I am most confused with the "MethodInvoker updateGrid = delegate {m_grid.Datasource = ds.Tables[0];};
Thank you
private void CallBack(IAsyncResult ar)
{
// get the dataset as output
DataSet ds = m_invokeMe.EndInvoke(ar);
// update the grid a thread safe fasion!
MethodInvoker updateGrid = delegate
{
m_grid.DataSource = ds.Tables[0];
};
if (m_grid.InvokeRequired)
m_grid.Invoke(updateGrid);
else
updateGrid();
}
eatwork
|
|
|
|
|
eatwork wrote: I am most confused with the "MethodInvoker updateGrid = delegate {m_grid.Datasource = ds.Tables[0];};
Well I could try to introduce the concepts to you ......... or I could use Google to find an MSDN Article[^] .... guess which option I went with?
led mike
|
|
|
|
|
Hi led mike,
Thanks for your help. I was able to create a seperate function and delegate in place of his delegate code. Still don't understand what exactly his code does, but I got it to work some how. Thanks again
eatwork
|
|
|
|
|
We have several web applications (C#, asp.net 2.0) that are very 1996 looking. We want to update the look of the applications without changing much of the functionality (for now). Is there an easy way to do this? Some good articles? Good resources? I would like to stay in Visual Studio and not use something like DreamWeaver.
Thanks, Jessica
|
|
|
|
|
It really depends on how the front-ends are laid out. You can generate modern funky looking sites with CSS, so if your site isn't too table heavy I would suggest trying out CSS.
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Can I send a picture of my Wife? She PRETTY! Well in my mind!
|
|
|
|
|
Hello,
I've just come across the Equals() method and I'm not sure about its correct semantics. Let me clarify with an example:
<br />
public class Tester<br />
{<br />
public int a; <br />
public int b; <br />
public int c; <br />
<br />
public Tester(int a, int b, int c)<br />
{<br />
this.a = a; <br />
this.b = b; <br />
this.c = c; <br />
}<br />
<br />
public override bool Equals(object obj)<br />
{<br />
if (this.GetType() == obj.GetType())<br />
{<br />
Test test = obj as Test; <br />
<br />
if ((this.a == test.a) && (this.b == test.b))<br />
return true; <br />
else<br />
return false; <br />
}<br />
else<br />
return false; <br />
}<br />
} <br />
Two objects of class Tester shall be equal if members int a, int b are equal - independent of int c. The content is being checked, not references. May I actually do this or are there any concerns?
Thanks for your help,
Goebel
|
|
|
|
|
Goebel wrote: May I actually do this or are there any concerns?
Read the discussion of "operator overloading" in Effective C++ by Scott Meyers
led mike
|
|
|
|
|
The members are native data (value) types, so ((this.a == test.a) && (this.b == test.b)) will properly evaluate to a boolean expression. The runtime already knows how to test for integer equality, so the logic you present should work just fine.
A few things to keep in mind, the as operator will return null if obj is not an object of type Tester (I assume you meant Tester and not Test as you have in your example) so you should test that test is not null before using it. You really should test to make sure obj isn't null as well.
The modified method would look like this:
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
Tester tester = obj as Tester;
if (tester == null)
{
return false;
}
if ((this.a == tester.a) && (this.b == tester.b))
{
return true;
}
else
{
return false;
}
} Also, you should also be overriding the GetHashCode(), equality, and inequality operators.
Finally, you should consider deriving your class from IEquatable<T> if you are using .NET 2.0/3.0 and implement the following functions:
public bool Equals(Tester obj)
and
public static bool Equals(Tester t1, Tester t2)
although the static method is optional but convenient
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Thanks Scott,
exactly what I needed. You hit the nail on the head! Much appreciated.
Cheers,
Goebel
|
|
|
|
|
hai friends
i want to generate word document by populationg it with the values fethed from sql server database
can u tell me thay way to do it
explore the world of imagination and be known as creative
|
|
|
|
|
Ista wrote: LookupItem<t.gettype()> li = new LookupItem<t.gettype()>();
As far as I understand generics, this cannot work. Generics allow you to write code that is able to deal with unknown types in a type-safe way, but to be type-safe a concrete type has to be specified when the code is used. In your case the result of t.GetType() is unknown, so that type-safety cannot be guaranteed. I think you have to do it the none-generic way using Object or a base class.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
actually you can create the type via reflection to bind against.
I worked it out so it can be binded at design time and I get generic binding with abstract types.
the final resulting call was this:
LookupList<LookupItem<TopicType>> list = (LookupList<LookupItem<TopicType>>)li.Load(LookupTypes.TOPICTYPE);
So it worked and allowed me to use generics to bind, so I get type safety. The power of generics with reflection is boundless.
wow
thanks for helping.
nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|