|
This will not work if your intent is to synchronize access to the MyType instance. You are only holding the lock while getting the reference to the instance. You then return the instance to the calling code which may then use it without synchronization.
The solution depends on what the calling code does with the MyType instance. You could expose a synchronization object in the Manager class, but that is open to abuse. Or you could add methods for manipulating the instance through the Manager class and use locks in those methods. YMMV.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Thank you for you answer Nick.
That was actually why asked this, I had a bad feeling about that
MyType is some kind of generic List. I wanted to ensure that I had exclusive access to the list as long as I was manipulating it.
Stupid idea now
I will expose the lock and acquire it as long as I am manipulating the list.
Phil
I won’t not use no double negatives.
|
|
|
|
|
|
Philip. Your concept of locking an object while returning a reference to it as a means of synchronization indicates you are far from understanding the fundamental concepts of synchronization. I strongly urge you to study the subject more before attempting any implementation requiring thread synchronization.
|
|
|
|
|
I'll do that.
I won’t not use no double negatives.
|
|
|
|
|
Philip F. wrote: I'll do that.
Then you will do well.
If it helps you, back when I started trying to understand mulit-threading I found Jeffery Richters book Advanced Windows[^] extremely helpful. Keep in mind it was the first edition so no guarantees the new one is the same.
|
|
|
|
|
OleDbConnection thisConnection = new OleDbConnection(
@"Provider = Microsoft.Jet.OLEDB.4.0;Data Source=e:\DataMoney.mdb");
OleDbDataAdapter thisAdapter = new OleDbDataAdapter(
"SELECT * FROM SchoolMoney", thisConnection);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "SchoolMoney");
OleDbCommandBuilder thisBuilder = new OleDbCommandBuilder(thisAdapter);
thisBuilder.QuotePrefix = "[";
thisBuilder.QuoteSuffix = "]";
//set up keys object for defining primary key
DataColumn[] keys = new DataColumn[1];
keys[0] = thisDataSet.Tables["SchoolMoney"].Columns[0];
thisDataSet.Tables["SchoolMoney"].PrimaryKey = keys;
DataRow findRow = thisDataSet.Tables["SchoolMoney"].Rows.Find(this.textBox1.Text);
if (findRow != null)
{
//
}
thisConnection.Close();
}
}
}
can you tell me how i get the number of row about findRow thank you
|
|
|
|
|
do you mean the index of the row that was found?
if so use this line of code where your blank comment is...
int rowNum = thisDataSet.Tables["SchoolMoney"].Rows.IndexOf(findRow);
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi,
How can i serilize and deserilize a MouseEventArgs?
Thankyou,
YPKI
|
|
|
|
|
You can't, it's not serializable.
You can create a new serializable class that holds all the property you need, populate them starting from the MouseEventArgs instance you want to save and then serialize it.
BTW, don't double-post.
|
|
|
|
|
You would have be better changing the subject of your original post to describe the problem instead of reposting.
EventArgs is marked as Serializable but not MouseEventArgs.
You can recreate the MouseEventArgs and mark your version serializable - something like:
[Serializable]
public class MyMouseEventArgs :EventArgs
{
public MyMouseEventArgs(MouseButtons button, int clicks, int x, int y, int delta)
{
_Button = button;
_Clicks = clicks;
_X = x;
_Y = y;
_Delta = delta;
}
private MouseButtons _Button;
private int _Clicks;
private int _Delta;
private int _X;
private int _Y;
public MouseButtons Button { get { return _Button; } }
public int Clicks { get { return _Clicks; } }
public int Delta { get { return _Delta; } }
public Point Location { get { return new Point(_X, _Y); } }
public int X { get { return _X; } }
public int Y { get { return _Y; } }
public static implicit operator MyMouseEventArgs(MouseEventArgs e)
{
return new MyMouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta);
}
public static implicit operator MouseEventArgs(MyMouseEventArgs e)
{
return new MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta);
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Is there some logic\reason as to why MouseEventArgs can't be serialized? Thx
|
|
|
|
|
The reason is it was never marked as Serializable by Microsoft. The logic behind that... I have no idea, you would have to ask them.
|
|
|
|
|
Only classes that have an empty constructor can be serialized.
http://doubin.blogspot.com/
|
|
|
|
|
Yeah.... I copied the source code, added an empty constructor, and serialized it.
|
|
|
|
|
Hi all,
Let’s discuss and share your knowledge on this question!!
I am sure most of the member having this question in their mind and as many as members knows the answer for this!!
Mean while, you can also ask your queries to other on same topic!!!
|
|
|
|
|
By default, parameters are passed by value.
Click me[^]
|
|
|
|
|
Groan.. I know where you're coming from - for reference types, references to objects are passed by value by default. "Passed by reference" is not entirely accurate, but it describes the object sharing aspect well.
|
|
|
|
|
Depends on whether the parameter is a reference type or a value type?
|
|
|
|
|
By default, by value (a copy).
If the parameter is a value type, it's a "copy" of that value.
If the parameter is a reference type, it's a "copy" of that reference (by reference).
If you use ref or out:
If the parameter is a value type, you pass a reference (address) to it.
If the parameter is a reference type, you pass a reference to this original reference which refers to the object. As an example of this, write a function that takes 2 arrays and swaps them (without copying the elements).
Eslam Afifi
|
|
|
|
|
If reference(from stack) to the reference type(e.g object)is passed then, whatever changes done inside the functions are reflected to the object (as another copy of reference is created on stack which also point to original location e.g object)..........isn't it??
then what is the use of ref and out keyword here???
anybody like share??
|
|
|
|
|
class A
{
public Guid Guid;
public A()
{
Guid = Guid.NewGuid();
}
}
static void Main(string[] args)
{
var a = new A();
Console.WriteLine(a.Guid);
Foo(a);
Console.WriteLine(a.Guid);
}
static void Foo(A par)
{
Console.WriteLine(par.Guid);
par = new A();
Console.WriteLine(par.Guid);
}
static void Main(string[] args)
{
var a = new A();
Console.WriteLine(a.Guid);
Foo(ref a);
Console.WriteLine(a.Guid);
}
static void Foo(ref A par)
{
Console.WriteLine(par.Guid);
par = new A();
Console.WriteLine(par.Guid);
}
Eslam Afifi
modified on Thursday, March 19, 2009 10:48 AM
|
|
|
|
|
deep@Pune wrote: then what is the use of ref and out keyword here???
ref and out pass the reference to the reference by value
|
|
|
|
|
Hello. I'm developing a Windows Mobille App, and i cannot allow users to leave the application, by clicking in start menu or side/down buttons. Can anyone help, please?
Thank you.
|
|
|
|
|
I'm developing a new steering-wheel, and I don't want you to use your brakes while you're in your car.
That didn't sound very nice, did it?
I are troll
|
|
|
|