|
Bob_Sun wrote: i was told lock(this) is not a good way.
And why didnt he back up his claim? It all depends what you need lock'd, but more important where the locking takes place.
|
|
|
|
|
|
What was wrong with the question you posted only half an hour before? Don't spam the forum.
---
b { font-weight: normal; }
|
|
|
|
|
Soory for made a mistake to post 2 messages.
I think it is better to use this thread only
|
|
|
|
|
Bob_Sun wrote: I think it is better to use this thread only
I already replied in the first thread.
---
b { font-weight: normal; }
|
|
|
|
|
Thank you very much.
I have read your following reply.
Who told you that it wasn't a good way, and what was the arguments for that?
I was just told so, and I found the following forum.
http://msdn.microsoft.com/msdnmag/issues/03/01/NET/[^]
Locking should of course be kept as a minimum, and to avoid deadlocks a thread should never lock more than one object at a time. Still, for sharing data between threads there is hardly any alternative.
I wrote a class for statemachine, whenever a event is dispatched, the whole statemachine should be locked in the thread. As for number of objects locked in this thread, it is always more than 2. As this is a statemachine, state changes must be sent to upper class. As the so called upper class collects messages from many child classes, messages are first enqueued before processed.
So, in this thread
lock(this)
{<br />
...<br />
lock(this)
{<br />
...<br />
}<br />
}
When several events occured in different threads, I suppose all of them will be locked at the first
lock(this) // Statemachine
before processed. Will this cause a deadlock in my program ?
|
|
|
|
|
If those are the only lock statements in the code, and they always get called in that order, it won't cause a deadlock. But if they always get called in that order, the inner lock is of no use at all.
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: If those are the only lock statements in the code, and they always get called in that order, it won't cause a deadlock. But if they always get called in that order, the inner lock is of no use at all.
First, the second lock(this) is not necessarily called every time, but when called the order is always the same. Second, the second lock(this) may also be called directly from other threads which have no relation to StateMachine(outside statemachine).
|
|
|
|
|
lock(this) can bring you in a deadlock
instead create a field like this:
private object syncRoot = new object();
and use
lock(syncRoot)
[EDIT] Not static field will be static only for static methods
|
|
|
|
|
Thank you very much.
lock( a private object )
was the good way introduced to avoid deadlock.
But why lock(this) brings about deadlock?
I want to find the case in which my program falls into a deadlock.
|
|
|
|
|
This article seems to mention a DeadLock
http://www.codeproject.com/csharp/lockmanager.asp
|
|
|
|
|
I need a guru's advice: I am porting datagrids over to gridviews, and have the following old code:
<br />
foreach (DataGridItem dgItem in dgClicks.Items)<br />
{<br />
CheckBox chkSelected = (CheckBox)dgItem.FindControl("chkSelection");<br />
if (chkSelected != null && chkSelected.Checked)<br />
{<br />
if (dgClicks.DataKeys[dgItem.DataSetIndex] != System.DBNull.Value)<br />
{<br />
int nTopupRequestID = (Int32)dgClicks.DataKeys[dgItem.DataSetIndex];<br />
<br />
BL.receipts.BlockCapturedTransaction(nTopupRequestID, edBlockReason.Text);<br />
}<br />
}<br />
}<br />
But I can't seem to figure out how to fix the second conditional in what I have written to convert.. I keep getting an operator overload error..
<br />
foreach (GridViewRow gvRow in gvClicks.Rows)<br />
{<br />
CheckBox chkSelected = (CheckBox)gvRow.FindControl("chkSelection");<br />
if (chkSelected != null && chkSelected.Checked)<br />
{<br />
if (gvClicks.DataKeys[gvRow.DataItemIndex] != System.DBNull.Value):confused:<br />
{<br />
int nTopupRequestID = Convert.ToInt32(gvClicks.DataKeys[gvRow.DataItemIndex]);<br />
<br />
BL.receipts.BlockCapturedTransaction(nTopupRequestID, edBlockReason.Text);<br />
}<br />
}<br />
}<br />
I'm sure this is an easy fix for some of yu guys.. so what did I do wrong? Is there a better way to approach this with the GridView??
Hoping for someones kind assistance!
-Eric
Practice sesquipedalianism!
-- modified at 8:27 Friday 24th March, 2006
LETS SHORTEN MY QUESTION.. HOW WOULD YOU WRITE THIS WITH A GRIDVIEW, NOT A DATAGRID??
if (dgClicks.DataKeys[dgItem.DataSetIndex] != System.DBNull.Value)
|
|
|
|
|
I have a problem about lock in C#.
I have written a multithread program, but the other day, the program hung up suddenly.
I have checked the code throughly but i could find nothing wrong.
In order to realize sync., i use lock(this) at several places.
But to my dismay, i was told this is not a good way at all recently.
Can anyone give me some information about this?
Thank you
-- modified at 6:57 Friday 24th March, 2006
|
|
|
|
|
Who told you that it wasn't a good way, and what was the arguments for that?
Locking should of course be kept as a minimum, and to avoid deadlocks a thread should never lock more than one object at a time. Still, for sharing data between threads there is hardly any alternative.
---
b { font-weight: normal; }
|
|
|
|
|
Why this methid AcceptTcpClient() takes much time to connectd and i can't connect.
Any idea????
_____________________
Proud to be Albanian
_____________________
|
|
|
|
|
Looks like your client is not trying to connect properly.
Ed
|
|
|
|
|
I never had that experience. Maybe something wrong with your code!
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
Hi,
I need to read a csv file...I m using OleDB Connection for this i have done this code...
OleDbConnection conCSV = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + dirName + ";Extended Properties='Text;HDR=Yes;FMT=Delimited;IMEX=1'" );<br />
<br />
OleDbDataAdapter daDBF = new OleDbDataAdapter<br />
( "SELECT * FROM " + fileName, conCSV );<br />
<br />
daDBF.Fill( DS, "Bids" );<br />
<br />
DS.WriteXML( TestFilePath );
But I m not Getting Full Data out, From CSV file some of the Data gets Truncated On Server It's Working fine On My local Machine...
Can Anybody sort out this...Pls
Thanx & Reagards
Anuj Kamthan
Software Developer
Solversa Technologies,
Pune - 411007, India.
http://www.solversa.com
-- modified at 6:11 Friday 24th March, 2006
|
|
|
|
|
See if you can do something like daDBF.CommandTimeOut(3000); or something.
You should set the OleDBCommand.CommandTimeout setting higher than the default 30 seconds first t see if it rectify's the situation..
Practice sesquipedalianism!
|
|
|
|
|
Thanks a lot for your interest
But Problem is different it's not because of timeout...
When i m reading the csv file and filling it in to dataset...whole records ll copied in to dataset but, there is an column in my csv file "Description" only this column's data ll truncate if it's very big...
Is there any limit in dataset...Can't save more then 255 character in a column.
Thanx
Anuj Kamthan
Software Developer
Solversa Technologies,
Pune - 411007, India.
http://www.solversa.com
|
|
|
|
|
I need C# Code to Show/Hide Quick Launch Bar.
|
|
|
|
|
Dont repost, you asked this yesterday... you will need to look in the WinAPI somewhere. I dont know where.
|
|
|
|
|
Hi..
How do i load the textfile i open into a richTextBox?
The best thing for me would be if i save this directory path that i choose in a "config file" so it saves there. Second i want to browse the text file (.scp) in my richTextBox.
<br />
private void btnOpen_Click_1(object sender, EventArgs e)<br />
{<br />
OpenFileDialog fdlg = new OpenFileDialog();<br />
fdlg.Title = "Emu Open File Dialog";<br />
fdlg.InitialDirectory = @"c:\";<br />
fdlg.Filter = "Emu Files (*.scp*)|*.scp*|Emu Files (*.scp*)|*.scp*";<br />
fdlg.FilterIndex = 2;<br />
fdlg.RestoreDirectory = true;<br />
if (fdlg.ShowDialog() == DialogResult.OK)<br />
{<br />
textBox20.Text = fdlg.FileName;<br />
}<br />
Anyone that can help me?
Regards
//Aeq...
|
|
|
|
|
You want to display the text of the .scp file into
the richtextbox , right?
This should work for u.
OpenFileDialog opdf = new OpenFileDialog();
opdf.ShowDialog();
richTextBox1.LoadFile(opdf.FileName,RichTextBoxStreamType.PlainText);
Hope that works fine for u
Regards,
Pramod
|
|
|
|
|
Hey guys, i'm wondering how I can bind DataGrideView to dataset, like data gride. so for instance when i click on a record in my DataGriedView I can have it in some Text Boxes for exiting.
Thanx
Mr.K
|
|
|
|