|
Hi all,
I always wondered, when using the lock statement, people lock other variables that the one which we want to serialize access to. Eg, if we want to serialize the call to a static int(varname++;), why do we chose to lock on another variable? Do we assume that whenever we will want to access this variable again, we're going to check if this variable has been locked previously?
Thanks
|
|
|
|
|
They do it as a matter of convenience; the variables on which they lock will always exist.
In C#, for example, let's say we want to access an instance variable within the class from more than one thread running within the class. So, we'd lock on the instance of the class since we know the class exists since we're running those methods!
lock( this )
If we want to access a static variable within a class from more than one thread, we use the runtime information to lock on that class, since we know the class exists, since we're attempting to change the value of a static variable contained within it.
lock( typeof( MyClass ) ) .
I hope that makes sense.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I have a problem!
i have an Array of buttons, and all of the buttons are connected to one event, let us say OnClick Event, now when i get in to the Event function i Cust the sender to a temp button in the function but the problem is that i want or better say need the buttons indexes becaue i need to check the buttons around the selected one.
How can i solve this problem?
Thanks you all!
|
|
|
|
|
Store the button index in the button's Tag property
|
|
|
|
|
What do you mean?
please give e.g.
Thanks
|
|
|
|
|
What the last free name means is the following:
Button[] buttons = new Button[ numberOfButtons ];
for( int i = 0; i < numberOfButtons; i++ )
{
buttons[ i ] = new Button();
buttons[ i ].Tag = i;
buttons[ i ].Text = String.Format( "Button {0}", i );
} And, in your button click event handler
Button b = ( Button ) sender;
int buttonIndex = ( int ) b.Tag;
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
what about a Matrix? [,]?
|
|
|
|
|
Okay, I don't know the specific class Matrix to which you have referred. However, let's assume that you have a Matrix class that acts like an n x m array of object s. Then, you could have the following code:
Matrix m = new Matrix( n, m );
for( int i = 0; i < n; i++ )
{
for( int j = 0; j < m; j++ )
{
m[ i, j ] = new Button();
m[ i, j ].Tag = new int[] { i, j };
}
}
And you could then acess the button in your event handler like so:
Button b = ( Button ) sender;
int[] index = ( int[] ) b.Tag;
That would then contain your index where the row index is in the first entry of index and the column entry in the second.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
i have a point.
how to compare this condition
PointF point=new PointF();
point = x.Intersect(y);
first time i am getting (429.5,215) as point
next time i am getting (+infinity,NaN) as point
So I like to have point which is having values in the point(numerice values).but not infinity or NaN
for this only I need to write (If condition).
if(point is not infinite)
{
}
if point is infinite then it not should enter in the if condition.
sometimes i get infinite values in the point.
what is the syntax for the above one.
Please help me out.
Thanks in Advance
Satya
satya
-- modified at 8:07 Friday 25th November, 2005
|
|
|
|
|
PointF holds onto 2 float values... float, like any other datatype, has finite values - what do you mean by the following line
satish0909 wrote: i get infinite values in the point
|
|
|
|
|
Something like this:
PointF point;
if (!float.IsInfinity(point.X) && !float.IsNaN(point.X) &&
!float.IsInfinity(point.Y) && !float.IsNaN(point.Y))
{
}
|
|
|
|
|
After years of development I get to my first multilanguage application, and I have a problem.
The windows forms part is almost ok: create the form with localize true, design it for default, after that load the form for every language, edit every text of every component - quite annoying.... but it works.
The problem is with strings (messages to the user). My first idea was to store them as resource strings, but resource does not have a language so a winforms-like approach not works. Now I store strings in external text files but this way is plain ugly.
Please, please shed some light - what would be the good way...
(using Visual Studio 2005)
|
|
|
|
|
Have you tried creating a resx file for each language using the appropriate name (see the name of the resx files created by Visual Studio for the dialogs to determine the name)?
Sorry I can't say anything for sure, I have only been doing enterprise level localization which involved a home build localization tool compiling the resx files. If you are going to do a reasonable size project, or more than one or two languages, consider buying a localization tool - they work MUCH better than VS (even though the tools you an buy are actually pretty bad they do have basic functionality missing in VS).
|
|
|
|
|
do any one of you know this namespace PointOfService is inherited from which dll. if any one of you know please reply me...its urgent.l
Raheel Iqbal
|
|
|
|
|
POS for .NET consists of two assemblies, Microsoft.PointOfService.dll and Microsoft.PointOfService.ControlBase.dll.
Source[^]
|
|
|
|
|
hi
i need help - i need to save information (STOCKS information)
from this site :
http://today.reuters.com/stocks/Overview.aspx?ticker=msft
i need to write a program in C# that get the information
and print it
Eyal
eyalso
|
|
|
|
|
//I have written the code on button click event.
//You also try the same ..It works
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Net;
private void button_Click(object sender, System.EventArgs e)
{
WebClient Client = new WebClient ();
Stream strm = Client.OpenRead ("http://today.reuters.com/stocks/Overview.aspx ticker=msft");
StreamReader sr = new StreamReader(strm);
string line = String.Empty ;
//listbox1.Items.Clear();
// create a writer and open the file
TextWriter tw = new StreamWriter(@"D:\date.xls");
}
do
{
line = sr.ReadLine();
if(line==null)
break;
//listbox1.Items.Add(line);
// write a line of text to the file
tw.WriteLine(line);
}
while(line!=null);
// MessageBox.Show(line);
sr.Close();
strm.Close();
// close the stream
tw.Close();
MessageBox.Show(@"File downloaded successfully at location D:\date.xls.");
}
Try this ...It works..
ajay_dalvi13@yahoo.co.in
-- modified at 6:13 Friday 25th November, 2005
|
|
|
|
|
|
Hi,
I am using OnSessionEnd Eventhandler in C#.
I am trying to invoke cmd.exe during system shutdown.
Whenever my program tries to invoke cmd.exe it fails and gives following error :
"The application failed to initialize properly (0x0000142)"
Pls find a solution for this ...
ajay_dalvi13
-- modified at 0:11 Monday 28th November, 2005
|
|
|
|
|
actually i want to make a combobox which has same features like combobox used in IE(Address Bar ComboBox). which has same features like AutoComplete and many more....
plz help me to solve this problem how would i make this kind of comboBox.
Amit Grover
|
|
|
|
|
What kind of answer do you expect? Complete source code?
You could start by looking at the various modified comboboxes here on CodeProject.
Clickety[^]
Otherwise just start with it and ask a bit more specific.
|
|
|
|
|
Hi,
Can anybody help me with this,
I want to display the data in the datagrid according to my requirement.Consider the following e.g,
I am a customer i have an unique customer id, i have multiple holdings, similarly there are many more customers.Now i want to display thisin my data grid as the first two column will have only one value i,e the customer ID and customer name, but in the same row the other cells will have multiple rows having details about each holdings of that customer
in short.1 customer will have many holdings, all details i need to show in a single row, but the column customername will have only one value.
Raghavan
-- modified at 1:56 Friday 25th November, 2005
|
|
|
|
|
try this code this might help you, change the code as per your needs.
protected string custid=null;
private void Page_Load(object sender, System.EventArgs e)
{
DataSet asd=new DataSet();
asd.Tables.Add();
asd.Tables[0].Columns.Add("Id");
asd.Tables[0].Columns.Add("name");
asd.Tables[0].Columns.Add("item_bought");
asd.Tables[0].Columns.Add("no_of_item");
asd.Tables[0].Columns.Add("item_price");
object[] qwe=new object[] {"1", "cust1" , "aaaa", "aaaaaa" ,"aaaaa" } ;
asd.Tables[0].Rows.Add(qwe);
object[] qwe1=new object[] {"1", "cust1" , "ssss", "sssss" ,"sssssssss" } ;
asd.Tables[0].Rows.Add(qwe1);
object[] qwe2=new object[] {"1", "cust1" , "ddddddd", "dddd" ,"ddddd" } ;
asd.Tables[0].Rows.Add(qwe2);
object[] qwe3=new object[] {"2", "cust2" , "fffffff", "ffffffff" ,"fffff" } ;
asd.Tables[0].Rows.Add(qwe3);
object[] qwe4=new object[] {"2", "cust2" , "ggggggg", "ggggggggg" ,"gggg" } ;
asd.Tables[0].Rows.Add(qwe4);
DataGrid1.DataSource=asd;
DataGrid1.DataBind();
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType.ToString()=="Item" || e.Item.ItemType.ToString()=="AlternatingItem")
{
string tmp;
tmp=e.Item.Cells[0].Text;
if(custid ==tmp)
{
e.Item.Cells[0].Text="";
e.Item.Cells[1].Text="";
e.Item.Cells[0].BorderStyle =BorderStyle.None;
e.Item.Cells[1].BorderStyle =BorderStyle.None;
}
if(custid ==null || custid !=tmp)
{
custid=e.Item.Cells[0].Text;
}
}
}
|
|
|
|
|
Good example, but why would you .ToString() ItemType when it is an enumeration that can be compared using the enum?
|
|
|
|
|
hi, I didn't knew it is an enumeration. thank to addin my knowledge
|
|
|
|