I had a second look at your code snippet. I guess that this
(on which you call Invoke) ist your control. You may try to call BeginInvoke on the delegate itself.
Tim Paaschen
Posts
-
delegate Question -
delegate QuestionTry
BeginInvoke()
for asynchronous execution of the delegate. -
inheriting from a class and also using a constraintThis one compiles (in VS2005): class BarStream<T> : IBarStream where T : Barable { } Regards, Tim
-
Source CodeNitin Raj wrote:
I need the source code for a software "HealthWatch Pro 2.0". how do i get it. Can someone please help me to get it.
I recommend you try the legal way: contact the manufacturer and ask for a quote. Regards, Tim
-
C# Generic: Is this a bug or by designmschuckmann wrote:
If you leave out the where constraint you've essentially specified a generic with a constraint of object and you can't call any methods except those declared by object. Therefore my example code will not compile without the where constraint. So sure you can impliment generics without type constraints but don't expect to do anything interesting in your generic code.
I do agree to your point of view, that the limitation of generics in regard to derived classes are unexpected. As a workaround you can use an interface, that defines the required methods, as the constraint. However, you must explicitly specify the interface for each class:
interface Named
{
void Name();
};class Base : Named
{
public void Name()
{
Console.WriteLine("I'm a Base class");
}
};class Middle : Base, Named
{
public new void Name()
{
Console.Write("I'm a Middle class");
}
};class Child : Middle, Named
{
public new void Name()
{
Console.Write("I'm a Child class");
}
};class Program
{
static void PrintName<T>( T instance ) where T : Named
{
instance.Name();
}static void Main( string\[\] args ) { Child c = new Child(); PrintName( c ); Console.ReadLine(); }
}
Regards, Tim
-
std::set to store pointersIf you store pointers in a set, the set is ordered by the pointer values (the addresses) and not by the values of your objects. You can either provide a customized comparer function object as the second template parameter or use the boost::ptr_set.
Regards, Tim
-
How to import a namespaceIf I remember correctly, the default namespace matches the name of the library. Use the "OLE/COM Object Viewer" (you find it in the Tools menu of Visual Studio), browse to the according Type Library and open it. Somewhere you will find something like:
[
...
]
library SERVERLib
{
...
}In this case
SERVERLib
will be the default namespace.Regards, Tim
-
How to import a namespaceI guess that you are talking of a COM-DLL and the
#import
directive. In this case you can use therename
attribute. If the COM-DLL already provides a namespace the attributerename-namespace
may be useful, too.Regards, Tim
-
Hey folks, that's funny... -
How to set date time format as "MM/DD/YYYY" for the entire application (including referring dlls)I typically set the
Application.CurrentCulture
property in addition to the thread properties. Are you sure that the DLLs make use of the thread's culture settings? Maybe their localisation is hard-coded or they utilize the OS culture (CultureInfo.InstalledUICulture
).Regards, Tim
-
Custom Collection ClassMartin# wrote:
Think about that again! ...
I never said that it is a good idea - just that it is technically possible.
Regards, Tim
-
Custom Collection ClassThis is a really strange idea! All possible keys must be known at compile-time. However, technically this can be achieved by adding a Dictionary member to you custom Collection and provide a property for each possible key that just wraps the indexer of the dictionary.
Regards, Tim
-
How to unregister a addin from MS Word?So how about "regsvr32 -u *.DLL"?
Regards, Tim
-
Interfacing between MATLAB and C++This article[^] should give you an introduction how to make a DLL from a MatLab code and how to use it from C/C++. However, to build the DLL (or an EXE) you will need the MatLab Compiler (mcc). If the mcc comand fails on your machine, you most propably don't have the MatLab Compiler installed. If I remember correctly, it is not part of the basic installation but must be bought separately (as many other MatLab toolboxes, too).
Regards, Tim
-
how to make .exe file by MatLabYou will have to buy the MatLab compiler.
Regards, Tim
-
Exception Handling: Object creation within try blockIf you provide a default constructor, I would recommend not to use a second constructor for your purpose. Instead provide a method. Currently you assign a new object within the try/catch-block and I'm not sure what happens to
s
, if an exception is thrown within the second constructor.Goebel wrote:
public class SampleClass
{
public SampleClass()
{
this.param1 = 1;
this.param2 = 1;
}public **Assign**(int param1, int param2) { int param1; int param2; if (param1 % param2 != 0) { throw new Exception(); } this.param1 = param1; this.param2 = param2; } public void Action() { // Some weird stuff in here. }
}
public class Tester
{
class Program
{
static void Main(string[] args)
{
SampleClass s = new SampleClass();try { **s.Assign(20, 20);** } catch (Exception e) { // Do processing here. } s.Action(); } }
}
Regards, Tim
-
Exception Handling: Object creation within try blockpublic class Tester
{
class Program
{
static void Main(string[] args)
{
SampleClass s = null;try { s = new SampleClass(20, 20); } catch (Exception e) { // Do processing here. **s = null;** } **if( s != null )** **{** s.Action(); // Compiler says: Use of unassigned local variable 's' **}** } }
}
This version should do the trick.
Regards, Tim
-
Blocking Multiple Application accessing the same fileAFAIK the
ReaderWriterLock
is local to a process. You will have to use a namedMutex
, that has system scope and thus can be shared between processes.Regards, Tim
-
passing "this" by referenceHi, as Luc already suggested, you can just drop the 'ref' from your method's parameter and everything should work. I will just add some explanation why you must not pass 'this' as a ref parameter. If you have a value object (a struct) and you pass it by value (no 'ref' parameter) to the method, the method gets its own copy and the original will not be affected by any changes made in the method. If the value object is passed by reference, all changes do affect the original. If you have a reference object (a class) and you pass it by value, the reference itself is copied. Thus you have two references to the same object. If the method changes the referenced object, the changes will affect the original. However, if the method changes the reference itself (e.g. set it to 'null'), this will not affect the original reference. If you pass the reference object as a reference parameter, you are able not only to manipulate the referenced object but also the reference itself. Sometimes this is the desired behaviour, but you definitely don't want enable any method to set your 'this' reference to 'null'. Therefore 'this' is read-only and must not be passed by reference. Hope this helps.
Regards, Tim
-
IsolatedStorage - How to store application config for more than one user?I typically use
Application.CommonAppDataPath
to store the global configuration files.Regards, Tim