|
thank Pete O'Hanlon for replying
my code just is a typical sample for deadlock. and I want to find a solution, in which using two locking objects, mentioned above.
|
|
|
|
|
numeracy wrote: I want to find a solution, in which using two locking objects, mentioned above.
Why? The whole reason we do this is to avoid the possibility of deadlocking. Have a read of this[^] article; while old, the techniques and ideas still apply.
|
|
|
|
|
I check your code. unfortunately, it's not true
output:
11111111111111111111111111111111111111111122222222222222222222222222222222222222
22222222222211111111111111111222222222222222222222222222222222221111112222222222
2222211111111111111111111111111111111111
all done
|
|
|
|
|
And what would you expect in code that runs in parallel?
|
|
|
|
|
in fact, i don't deeply understand multithreading
maybe output is that:
11111111111111111....(100 times)
222222222............ (100 times)
|
|
|
|
|
That part was left for you to figure out for yourself - what would you expect to happen if you couldn't acquire a lock? That's application specific, so I didn't put that in there, but you could check to see if you got the lock and loop until you got it in that function. All you need is to capture the return value of Monitor.TryEnter to control this.
|
|
|
|
|
multithreading is like having several workers in a factory: if you don't take any precautions they all will manufacture some goods at their own pace; you need explicit synchronization if you want the goods produced in a controlled order.
However, if all you want is
11111111111111111....(100 times)
222222222............ (100 times)
then multithreading isn't doing anything for you, and you could better just use a single thread and no locks.
|
|
|
|
|
This has a huge smell of homework about it, as this is a clearly contrived example. The simple answer is, you should never nest locks if you can possibly avoid it, and if you have to lock on multiple things simultaneously (which should be rare), you need to do it in a consistent order (i.e. always lock on obj1 and then obj2).
Since this example is so contrived it's not possible to have a sensible discussion about it; neither F1 nor F2 actually requires exclusive access to anything so the correct solution here wouldn't lock at all.
|
|
|
|
|
if i don't want to print any number (1 or 2), i want to go to deadlock "obj1" immediately, so how can i fix my code?
|
|
|
|
|
I have a MDI winform program, I create a child WinForm frmChild;
In this frmChild, I have a button Add to do some operation, after the operation is done, I want to destroy the frmChild form.
How can I do this?
OnBtnAdd()
{
do_operation();
}
|
|
|
|
|
Did you try Close()?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Dear all,
I set a label auto size is false, and dock is full in a pane, because label.text is dynamic words, it can't see some label text if we put much words! I want to make label font auto change when text is much!
How to do it?
Thanks
|
|
|
|
|
I guess you'd have to check the number of characters in the text, and change the associated font size property for the label. You could do this when the layout phase has finished. Be aware, though, that if the font size goes too small, your users won't be able to read the text.
|
|
|
|
|
Thanks for your answer
Do u know how to code it define a fit font size for current the number of characters in the text?
|
|
|
|
|
That's really going to be up to you. I don't know how big your label is - there's a reason for this knowledge, as you are going to have to use that as a basis for your scaling factor - it's going to be a bit trial and error for you.
|
|
|
|
|
In my Win32 days I did this using DrawText()[^] with DT_CALCRECT . Sorry, but I don't know of a .NET equivalent.
/ravi
|
|
|
|
|
Whenever u select the first dropdown button(india),
when automatically updated to next dropdown(andhra pradesh)........like this scenario
can u plz anybody give me the code........
|
|
|
|
|
|
R@vuri wrote: can u plz anybody give me the code........
The dreaded text speech asking for code
Look here[^] before posting questions.
In addition, please don't use text speech, write full sentences.
thanks.
V.
|
|
|
|
|
Hi,
If u select the check box like(gmail,yahoo),all the check boxes selected..........
can u anybody plz give me the code
R@vuri
|
|
|
|
|
try this javascript function
function SelectAll(cntrl,grd,indCat)
{
var grdComp = document.getElementById(grd);
if(indCat == '1')
{
for(i=1;i<=grdComp.getElementsByTagName('input').length-1;i++)
{
grdComp.getElementsByTagName('input')[i].checked = cntrl.checked;
}
}
else if(indCat == '2')
{
var chkInd = true;
for(i=1;i<=grdComp.getElementsByTagName('input').length-1;i++)
{
if(grdComp.getElementsByTagName('input')[i].checked == false)
{
chkInd = false;
}
}
grdComp.getElementsByTagName('input')[0].checked = chkInd;
}
}
hope this helps
with regards
Karthik Harve
|
|
|
|
|
|
The simplest solution is to run a loop through the checkboxes and then check / uncheck them.
There are other more complex solutions like using LINQ etc.
Try one that suites you best.
|
|
|
|
|
I had a MDI WinForm Program, when click from a menu item, I new a new child WinForm(this child WinForm designed in the designer), but this new child WinForm is not maximumed even I set the childForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
Could you show me how to do this? Thanks in advance!
|
|
|
|
|
if you want this child to be open as a separate maximized form then try this below code..
CHildForm frm = new CHildForm();
frm.WindowState=FormWindowState.Maximized;
frm.ShowDialog();
[or]
if you want this child to be open as maximized within the MDI parent, then try this..
CHildForm frm = new CHildForm();
frm.WindowState=FormWindowState.Maximized;
frm.Show();
hope this hepls.
with regards
Karthik Harve
|
|
|
|