|
There is an explanation about how to raise events in MSDN at the address below:
http://msdn2.microsoft.com/en-us/library/ms173168.aspx
It says:
To avoid a race condition where the last handler can be removed between the null check and the invocation of the event, event sources should also create a copy of the event before performing the null check and raising the event.
private void RaiseTestEvent()
{
// Safely invoke an event:
TestEventDelegate temp = TestEvent;
if (temp != null)
{
temp(this, new System.EventArgs());
}
}
But Isn't the delegate TestEventDelegate a reference type? If I'm right, then assiging the Event TestEvent to the temp variable should not make a seperate object with similar data and state. It should rather create another pointer to the same object as it's supposed to do in reference types realm. So even in the race condition mentioned above, creating the temp variable should not be a solution. Because in that situation, removing the last event will cause the temp variable become null just like TestEvent. However the code above works well and eliminates the race condition. This makes a confusion for me on how it's possible that the variables are reference types while the code works well.
Any idea?
|
|
|
|
|
Yes, when you copy the reference into the temp variable, you are only copying the reference itself, the object stays the same.
The reason that this prevents the reference from becoming null is that you have a copy of the reference. If the reference that is returned from the TestEvent property is changed to null, your copy of the reference is still unchanged and is still referencing the object.
---
single minded; short sighted; long gone;
|
|
|
|
|
Do you mean creating a copy of a reference type prevents it from becoming null when the copy is set to null and vice versa??? As far as I know, both of the variable must be referring to a same object. So any change in each one must be reflexed in the other one. I didn't get your meaning!
|
|
|
|
|
It's not the object that is changed to null, it's the reference.
The reference and the object are separate entities. Changing the object doesn't change the reference, and chancing the reference doesn't change the object. If you have a reference that points to an object and sets the reference to null, that doesn't change the object, it only makes it inaccessible through that specific reference.
Similarly, two references pointing to the same object are three separate entities. Changing the object doesn't change either reference, and changing one reference doesn't change the object or the other reference. Setting one of the references to null doesn't change the object and doesn't change the other reference.
---
single minded; short sighted; long gone;
|
|
|
|
|
I am trying to set the global value into into combobox and the value is not showing up in the combobox. Need help. Here is the code.
sql1 = @"SELECT locationNo, cast(locationNo as varchar) + cast(' - ' as varchar) + cast(locationName as varchar) as locationNames FROM Locations WHERE LocationNo = '" + VehicleGlobal.gv_Location + "'";
SqlDataAdapter da1 = new SqlDataAdapter(sql1, conString);
da1.Fill(ds, "Locations");
DataTable dt = ds.Tables["Locations"];
foreach (DataRow row in dt.Rows)
{
VehicleGlobal.gv_LocationName = row["LocationNames"].ToString();
}
this.cboLocation.Text = VehicleGlobal.gv_LocationName
|
|
|
|
|
try changing this
this.cboLocation.Text = VehicleGlobal.gv_LocationName
to
this.cboLocation.Datasource = VehicleGlobal.gv_LocationName
this may not work, it depends what type your VehicleGlobal.gv_LocationName property is.
|
|
|
|
|
hi,
I want to validate the onecolumn in datagridview like only digits entry.
By using keydown/keypress event how can i validate it for a perticular
column in Dtagridview.
Help me please
With Regards
prasad
|
|
|
|
|
|
try below line
if(Dtatgrid1.cells[row][col].value==?)
|
|
|
|
|
hi all,
I have set the password char for a textbox as *. and i am able to mask the password. I have a check box which prompts for showing the password.
Now how can i unmask the password char so that the password is visible in the textbox?
Thanks in advance.
Regards
Anuradha
|
|
|
|
|
You can change the textmode property of the textbox to single line again!
TextBox1.TextMode="SingleLine"
Gautham
|
|
|
|
|
hi gautham,
Thanks for the immediate response. I am using windows application in C#.
There is no textmode property for textbox control in windows application.
How to proceed?
Thanks once again.
Regards
Anuradha
|
|
|
|
|
Do the following
textBox1.PasswordChar = '\0';
|
|
|
|
|
hi,
Thanks for your help.I got it working.
Set the password char to \0 made to unmask my password.
Thanks for the help.
Regards
Anuradha
|
|
|
|
|
TextBox.PasswordChar Property
The character used to mask characters entered in a single-line TextBox control.
Set the value of this property to 0 (character value) if you do not want the control to mask characters as they are typed.
Equals 0 (character value) by default.
Gautham
|
|
|
|
|
Its just a trick...
1) Have a 2 textboxes which stores the password, one is masked and other unmasked at the same location having the same top,left,height and width.
At an instance depending upon the checkbox value, only one textbox is visible
if(checkbox checked true)
{
textboxMasked.Visibility = false;
textboxUnmasked.Visibility = true;
textboxUnMasked.Text = textboxMasked.Text
}
else
{
textboxMasked.Visibility = true;
textboxUnmasked.Visibility = false;
textboxMasked.Text = textboxunMasked.Text
}
In the check box unchecked event,do the above
Hope this solve ur issue...
please reply back if it solved ur requirement
N.Navaneethan
|
|
|
|
|
I need to do some math that involves truncating the number after the tenths place. So, I need to take some calculation and remove all digits after the first decimal place without rounding.
For example
3765/3700 * 100=101.75675675675675675675675675676
But, I need to produce from that calculation 101.7. Not 101.8 (the rounded form). Is there a built in method that performs this sort of calculation, or some other way that you might suggest? Thanks.
|
|
|
|
|
try math.ceiling or math.floor methods
Gautham
|
|
|
|
|
Hello,
If you want to show it as a string, you could use the String.Format method.
int numberofdecpoints= 10;
double d = 3765/3700 * 100;
string roundednumber = String.Format("{0:F"+ numberofdecpoints.ToString() +"}",d);
All the best,
Martin
|
|
|
|
|
May not be the prettiest
double d = 101.75675675675675675675675675676;<br />
string s = string.Format("{0:f2}", d);<br />
d = Convert.ToDouble(s.Remove(s.Length-1));
Using the specifier {0:f1} still rounds the number to 101.8, so use 0:f2 and truncate it.
only two letters away from being an asset
|
|
|
|
|
Can't you just do this?
<br />
double d = 128.158676;<br />
Convert.ToDouble(Convert.ToInt32(d * 10)) / 10;<br />
|
|
|
|
|
double d = 101.75675675675675675675675675676;
d = Math.Floor(10 * d) / 10;
Now d has a value of 101.7
Hope this helps
|
|
|
|
|
Help!
I need to convert bmp to pcx file? Does anyone have an idea?
Have problem using CXImageAtl.dll
Nataliya
|
|
|
|
|
hi everyone
i'm working with VS 2003 and can't find the create Class Diagram option.
can anyone please tell me how to make class diagram through VS 2003.
thanks for your time.
|
|
|
|
|
Saira Tanwir wrote: i'm working with VS 2003 and can't find the create Class Diagram option.
can anyone please tell me how to make class diagram through VS 2003.
There isn't one. It is a new feature of Visual Studio 2005.
|
|
|
|