|
Rome` wrote: the designer code will be regenerated
If you are using VS2005, it is safe to modify the Dispose method in the .Designer.cs file. Otherwise, you are right and may have an issue (it's been too long since I've used the earlier versions so I'm not 100% sure if they will overwrite the Dispose method when regenerating the designer generated code).
Rome` wrote: GridVoucher.Click -= new (GridVoucher_Click); be enough
If you double check the code in my previous post, you will see that I am actually calling GridVoucher.Click -= GridVoucher_Click; . There is no new call. Technically, the GridVoucher.Click -= new(GridVoucher_Click); is creating a new event handler delegate with the same signature as the previous one and then unregistering it, which ultimately causes both to be unregistered. It's a little bit quirky that you can do this, but it does work. However, the better approach is to use the GridVoucher.Click -= GridVoucher_Click; syntax as this prevents an additional object from being created. Remember, this is all happening as the class is being disposed, so you want to make sure things happen as quickly and efficiently as possible. You should avoid creating new objects inside the Dispose whenever possible.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Scott Dorman wrote: If you are using VS2005, it is safe to modify the Dispose method in the .Designer.cs file. Otherwise, you are right and may have an issue (it's been too long since I've used the earlier versions so I'm not 100% sure if they will overwrite the Dispose method when regenerating the designer generated code).
I know VS03 doesn't touch dispose within a form after the initial creation, so I'd assume it's safe for a control as well.
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|
|
Hello Scott,
As I read this post two weeks ago, I was really impressed about the possiblity to unregister events without instanciating a new event handler delegate. (So I voted "5" for it)
I now whanted to test it in my application with a System.Windows.Forms.Timer.Tick event and found out that it's not compiling.
I'm using VS2003 .Net1.1!
tmrSession.Tick -= new EventHandler(tmrSession_Tick); //compiles fine
tmrSession.Tick -= tmrSession_Tick; //error: blablabla... usage without quotation mark
tmrSession.Tick -= "tmrSession_Tick"; //does of course not compile and makes no sence at all. (string confersion to ...)
Hope you can help me out!
Thanks for your time and help!
All the best,
Martin
|
|
|
|
|
Martin,
Can you provide the actual error message? I don't have access to VS2003 anymore, but this syntax should work.
Adding the event handler should be tmrSession.Tick += new EventHandler(tmrSession_Tick); and removing the event handler should be tmrSession.Tick -= tmrSession_Tick;
It is possible that .NET 1.1 didn't support this syntax, but I don't think that is likely since this is really just delegate management and I don't think the underlying architecture changed much between .NET 1.1 and 2.0.
Scott.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Hello Scott,
Thanks again for your time!
I only have German version of VS2003, so I have to tranclate it in my words.
There is a reference on the method 'tmrSession_Tick(object, System.EventArgs)' without the usage of quotation marks!
Regards
Martin
|
|
|
|
|
Could you post (or email) the relevant snippets of code? Even though I don't have VS2003 anymore, I might be able to see if the code looks correct. I verified with the System.Windows.Forms.Timer object that I can do the following with VS2005:
this.timer1.Tick += new EventHandler(timer1_Tick);
this.timer1.Tick -= timer1_Tick; Thanks,
Scott.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Hello Scott,
Thanks for your quick answer and interest.
But I did exactly the same you posted and failed at compilation like posted before.
I don't whant to waste your time anymory, but I'm really thankfull that you tried to help me.
I relly think now that VS2003 doesn't support this feature!
May I have a quick look at google.
All the best,
Martin
|
|
|
|
|
Martin,
It does sound like VS2003 does not support this syntax. Sorry I wasn't able to help you resolve the problem, but it certainly wasn't wasting my time. If you are able to find out if this syntax works I would definately like to know.
Thanks,
Scott.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Scott Dorman wrote: Sorry I wasn't able to help you resolve the problem, but it certainly wasn't wasting my time.
Scott Dorman wrote: If you are able to find out if this syntax works I would definately like to know.
I definitely will!
|
|
|
|
|
I have created the datarelation from the datatables of dataset. but i don't know how to bind the resultset of datarelation to the datagrid control.
please let me know.
thanks in advance
|
|
|
|
|
I'm just using :
this.myDataGrid.DataSource = myDataSet;
|
|
|
|
|
this.myDataGrid.DataSource = myDataSet;
only the first datatable of the dataset will be assigned to the datagrid if we use the above syntax. But i have to use the datarelation of the dataset. what should do for that?
thanks a lot for your response.
thanks in advance
|
|
|
|
|
Hi everyone, I'm trying to use a column from my database as a checkbox, any idea how to do it?? What's the retrieved value of it's checked/uncheced state?? is it numeral, textual, byte, boolean and how to get this value.. please help.
Note: I tried to customize a VARCHAR2(22) field from ORACLE and I keep getting this error:
Cannot set column 'MyCheckBoxColumn'. The value violates the MaxLength limit of this column.
Thanx a bunch guyz
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
I have used bit datatype in sql. So it would be 0 or 1 which seems to translate nicely to true and false which is what you need for a checkbox.
Hope that helps.
Ben
|
|
|
|
|
kubben wrote: Hope that helps.
Thanks but no
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Dear gurus,
I have the following problem.
After building my project, I want to copy in a "post-build-step" files from anywhere to my exe-directory. But I only want to copy if files are not present already or if files are newer.
Can anybody give me a hint how to perform this?
Thank you in advance
|
|
|
|
|
Make your post build step a program that does exactly what you want.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello All,
I want to show an animated gif one of the DataGridViewColoumns, but it shows like static image. Do you have any suggestion? Thanks...
|
|
|
|
|
Can anybody pleae explain me , if possible with exmamples, the different purposes of using SyncRoot property and Synchronized methods?
|
|
|
|
|
SyncRoot Property:
Gets an object that can be used to synchronize access to the collection.
public virtual object SyncRoot {get;}
Property Value:
An object that can be used to synchronize access to the collection.
Synchronized Methods:
Synchronisation plays an important role in multithreaded applications where the threads are not independent of each other and share common resources. This is because if two threads share common resources and try to manipulate the resources simultaneously, the resources become inconsistent. To tackle such situations synchronisation provides a lock on the resource that is shared among threads and makes a thread wait until the other thread finishes the job with the resource. Thus synchronisation ‘locks’ the shared resource and prevents another thread from using it.
C# provides a lock keyword to lock the shared object or resource. Whatever is written inside the parenthesis following the lock keyword gets locked for the current thread and no other thread is permitted to obtain the lock on that resource or object. We can write an expression that evaluates to an object, or just the object on which we wish to have a lock, inside the parenthesis. Whatever the expression may be, the result should be a reference type. The code that uses the object to be synchronised should be written inside the block of the lock statement.
To give you a more concrete example, consider two threads working on a file. If both the threads try to open the file and write to it simultaneously, an exception is thrown. Here what we need to do is synchronise both the threads in such a way that only one thread opens the file and writes in it at any given moment.
Regards,
Satips.
|
|
|
|
|
Any code snippets please?
|
|
|
|
|
Now if the user supplies some number in the textbox and clicks on the purchase button, the following handler gets called:
In this Sample Code
FileInfo f;
FileStream fs;
byte total=100;
f = new FileInfo ( “C:\\log.bin” );
Thread t = new Thread (new ThreadStart(checker));
t.IsBackground = true;
t.Start();
<br />
private void purchase_Click ( object sender, System.EventArgs e )<br />
{<br />
lock ( f )<br />
{<br />
try<br />
{<br />
fs = f.OpenWrite( ) ;<br />
byte b = byte.Parse ( quantity.Text ) ;<br />
total = ( byte ) ( total - b ) ; <br />
fs.WriteByte ( total ) ;<br />
MessageBox.Show ( "Transaction Complete" + "\n" + "Item <br />
remaining: " + total ) ;<br />
fs.Close( ) ;<br />
}<br />
catch<br />
{<br />
MessageBox.Show ( "Cannot Open file" ) ;<br />
}<br />
}<br />
}<br />
Regards,
Satips.
|
|
|
|
|
Synchronized returns a collection that locks on each call, i.e. while you call a method or property, no other thread may modify the collection. This is convenient, but not enough.
Imagine the following code snippet:
if (myList.Count > 0)
myList.RemoveAt(0);
In this case, you have two separate calls (querying "Count" and removing an object). However, between the calls, some other thread may access the list and e.g. clear it completely. In this case, RemoveAt will fail.
For that scenario, you get the SyncRoot:
lock(myList.SyncRoot)
{
if (myList.Count > 0)
myList.RemoveAt(0);
}
|
|
|
|
|
Thanks Peter, But still i am not clear.
First point is, if we synchronize the whole method, how other thread can make calls between Count and RemoveAt?
Secondly, instead of lock(mylist.syncRoot) can't we specify lock(mylist)?
|
|
|
|
|
kumar.bs wrote: if we synchronize the whole method, how other thread can make calls between Count and RemoveAt?
They can't (as long as they use the lock), and that's the whole point. because between "Count" and "RemoveAt" noone may modify the list.
Keep in mind that querying Count is usually very fast, so lock acquisition and RemoveAt will take the majority of execution time anyway.
kumar.bs wrote: lock(mylist.syncRoot) can't we specify lock(mylist)?
Two problems:
First, "List Proxies". The synchronization works correct only if all threads accessing the list use the same object to lock on. However, the List interface might not hold the data itself, but expose the interface for some underlying data. If one thread lokcs on the list proxy, and another thread locks on the underlying data, we have the concurrent access we need to avoid.
Second, Lock Order.
There is a problem wiht locking on publicly visible symbols. When you have two locking objects A and B, one thread might lock in the order A, B the other in order B,A. This leads to a deadlock situation that cannot be solved.
That's why locking on public objects is almost always a bad idea. You need to be very clear which lock objects exsit in your code (and the code you call!), and give them a definite order. SyncRoot helps here a little bit since it is a dedicated object used for locking, that is provided by the underlying data.
helped?
|
|
|
|