|
hi,
Can anyone explain how I can attain the following senario
What I have to do to display a warning message when I change the focus or try to edit another row, without entering valid data in the mandatory cells(fields) of the previous row
thnks.
|
|
|
|
|
Have you resolved this?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I have a class that i want to be able to use in a asp.net app or a win app. I want this class to be thread safe. I have the following code in my event method
public void OnTransactionStarted(object sender, TransactionStartedEventArgs e)
{
ISynchronizeInvoke sync = this as ISynchronizeInvoke;
if (sync.InvokeRequired)
{
TransactionStartedEventHandler tmp = new TransactionStartedEventHandler(OnTransactionStarted);
object[] args ={ sender, e };
sync.Invoke(tmp, args);
return;
}
if (TransactionStarted != null)
TransactionStarted(sender, e);
}
I cannot get the ISyncorizeInvoke object from my class. I tried making this class a component and i still was not able to make this work. The only way i can make this code work is by implement the "WebControl" or "Control" object. I do not want to make this specific for an asp.net app or a win app.
I tried to inherit the ISyncronizeInvoke interface but i did not know what to do from there. I want to make this class as simple and elegent as possible.
Any suggesions? Thanks in advance!
|
|
|
|
|
What kind of class are you creating? Implementing ISynchronizeInvoke does not make your class thread-safe. If your class isn't a "control", then you should use other methods (e.g. Monitor, lock, ReaderWriterLock) to make your class thread-safe.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I am using lock method to make my class threadsafe. I am trying to avoid getting cross-thread errors in a multithreaded environment. This is what ihave done so far:
public void OnTransactionEnded(object sender, TransactionEndedEventArgs e)
{
ISynchronizeInvoke sync = null;
if (TransactionEnded != null)
sync = TransactionEnded.Target as ISynchronizeInvoke;
if (sync != null) //sync would be null if used in ASP.NET and would have the ISYnchronizeInvoke object if used in winforms
{
if (sync.InvokeRequired)
{
TransactionEndedEventHandler tmp = new TransactionEndedEventHandler(OnTransactionEnded);
object[] args ={ sender, e };
sync.Invoke(tmp, args);
return;
}
}
if (TransactionEnded != null)
TransactionEnded(sender, e);
}
What do you think of this solution?
|
|
|
|
|
Since I don't understand what your class is used for I can't give advice as to the solution. Is this a control that has some UI (e.g. an web control or a win form control)? If not, then you really shouldn't be taking cross-thread errors into consideration. A non-UI class should really just be concerned with making sure it's state is maintained when read or updated by multiple threads.
The only exception I can really think of is if your class fires events. In this case you could follow this article[^]. This offloads the responsibility of invoking UI changes on the UI thread from the consumer of your class. Although, there may be times when no UI changes are required and it would have been better to allow the consumer to decide whether it needs to call Invoke/BeginInvoke. In general for non-UI classes, I don't use this technique.
If you can describe more about your class and how it interacts with the UI, then I can give more specific advice.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Creating a class that follows a "plug and play" model where it can be refrenced by any application(asp.net or winforms) that allows the programmer to use this class without worrying about thread safety(using lock) or syncronization (cross-threading). This class will can be used in a multi threaded environment or a single thread environment. This class will have events that notifies the programmer of 'transaction' statuses. This class will not be dependent on a specific UI component (win control or web control).
Plan:
Create a class that lock object while being used. Also, when the event is triggered, this class will check to see if thread sync is required. If it is, thread will be synced else thread will not be synced.
I hope I have provided enough information for you to be able to judge ifthis is a good solution. Thanks for your prompt replys!!!! The class code is below.
Class Code:
public class BaseObjectClass
{
//Private Fields
private object syncObject;
//Events
public event TransactionStartedEventHandler TransactionStarted;
public event TransactionEndedEventHandler TransactionEnded;
//Consturctors
public BaseObjectClass()
{
syncObject = new object();
}
//Event Methods
public void OnTransactionStarted(object sender, TransactionStartedEventArgs e)
{
//ISynchronizeInvoke sync = this. as ISynchronizeInvoke;
ISynchronizeInvoke sync = null;
if (TransactionStarted != null)
sync = TransactionStarted.Target as ISynchronizeInvoke;
if (sync != null)
{
if (sync.InvokeRequired)
{
TransactionStartedEventHandler tmp = new TransactionStartedEventHandler(OnTransactionStarted);
object[] args ={ sender, e };
sync.Invoke(tmp, args);
return;
}
}
if (TransactionStarted != null)
TransactionStarted(sender, e);
}
public void OnTransactionEnded(object sender, TransactionEndedEventArgs e)
{
ISynchronizeInvoke sync = null;
if (TransactionEnded != null)
sync = TransactionEnded.Target as ISynchronizeInvoke;
if (sync != null)
{
if (sync.InvokeRequired)
{
TransactionEndedEventHandler tmp = new TransactionEndedEventHandler(OnTransactionEnded);
object[] args ={ sender, e };
sync.Invoke(tmp, args);
return;
}
}
if (TransactionEnded != null)
TransactionEnded(sender, e);
}
public virtual object Insert()
{
lock(syncObject)
{
OnTransactionStarted(this, new TransactionStartedEventArgs(ItemCommand.Insert));
//Some Code
OnTransactionEnded(this, new TransactionEndedEventArgs(ItemCommand.Insert));
return s;
}
}
public virtual bool Update()
{
lock(syncObject)
{
OnTransactionStarted(this, new TransactionStartedEventArgs(ItemCommand.Update));
bool updated = false;
//Some COde
OnTransactionEnded(this, new TransactionEndedEventArgs(ItemCommand.Update));
return updated;
}
}
public virtual bool Delete()
{
lock(syncObject)
{
bool deleted = false;
OnTransactionStarted(this, new TransactionStartedEventArgs(ItemCommand.Delete));
//Some Code
OnTransactionEnded(this, new TransactionEndedEventArgs(ItemCommand.Delete));
return deleted;
}
}
}
|
|
|
|
|
In that case, I would follow this article[^] (same as the one in my previous post). This works similar to your implementation, but handles the case where there are multiple listeners to your event.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Are you building a control for a form?
Phil
|
|
|
|
|
How do I create menu items with several sub menu items in .NET?
M.
|
|
|
|
|
Hi,
- graphically, use Visual Designer
- programmatically: MainMenu, ContextMenu and MenuItem all inherit from Menu,
which has a MenuItems property, so you can build an entire tree of Menus by adding
MenuItems where ever you want.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Two questions!
By using GACUTIL!
Is there any way to remove all the assemblies of a particular public key token from GAC?
By using NGEN!
Is there any way to remove all the assemblies of a particular public key token from native code cache? AFAIK the command "NGEN uninstall *" removes all assemblies from native code cache.
Best Regards,
Mushq
Mushtaque Ahmed Nizamani
Software Engineer
Ultimus Pakistan
|
|
|
|
|
ngen /uninstall allows you to specify an individual assembly that you want to remove. So no, there's no easy way.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
what are the best c#.net components for processing OCR and digital cameras?
|
|
|
|
|
Has a simple google search turned up anything?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
MC# is a new programming language for all types of parallel architectures:
multi-core processors, cluster and Grid. It's high-level constructs as async- and movable methods,
channels and handlers provide ways to increase dramatically a productivity of programmers who develop
concurrent and distributed applications.
MC# 2.0 programming system (www.mcsharp.net) main features are
1) dynamic workoad balancing over multiple cores/processors and
2)integration with Microsoft Visual Studio 2005.
|
|
|
|
|
If this is an advert then you should be speaking to the site owners about purchacing advertising space.
|
|
|
|
|
This looks like spam to me. Trying to get free advertising by posting a note in a forum. Sorry, it takes money to run the servers and pay for the pipe your using to get your "free" advertising. Support the site by buying ad space.
|
|
|
|
|
One word - pillock.
-- modified at 17:08 Thursday 20th September, 2007
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete O`Hanlon wrote: One word - berk.
berk?
|
|
|
|
|
Cockney rhyming slang[^]. Although I was unaware of this connotation - I will not be using this one anymore as it's a phrase that I don't like. It also means a person who is a bit of a jerk.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks for the clarification. The meaning of "a person who is a bit of a jerk" is good, but as for the other connotation...I agree with you on that one.
|
|
|
|
|
I've modified it now to pillock. That's generally used for somebody who's a bit foolish.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
Hi all,
I've got a C# WinForms application where the top-level form displays a modal dialog to allow the user to set some options. I create it very simply as follows:
using (MyForm form = new MyForm())
{
form.ShowDialog(this);
}
I've turned off the ShowInTaskbar property for the dialog, so it doesn't show up in the taskbar. However, if you press Alt-Tab, it appears in the window list. That itself is not too much of a problem (it just looks bad and can be a little annoying if you're trying to switch between two apps).
However, you can use Alt-Tab to switch back to the parent form even though it is currently showing the modal dialog. I'm unable to use the mouse to do anything with the parent form, BUT I can use keyboard accelerators to use menus on the parent form (with bad consequences). I've worked around this by explicitly disabling and enabling the parent form while displaying the dialog.
So I have two questions:
1) Any ideas for how I can stop my modal dialog appearing in the Alt-Tab window list? I presume it appears there because it is a top-level form, but .NET doesn't seem to like showing non-top-level forms as modal dialogs.
2) Is the approach of disabling and enabling the parent the best approach here? Or am I just missing something obvious?
Thanks,
Dave
|
|
|
|