|
|
Wow, thanks a lot!
|
|
|
|
|
Glad to help you
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Thanks for a great link!
|
|
|
|
|
Wow, what an old thread. Always happy to help you Luc!
|
|
|
|
|
I've written a plug-in architeture based application. Plugins exist in isolated assemblies and each plugin runs in it's own thread provided by the host application. But these plugins just cannot display their own forms. Exactly, they can, but it's just a "flash". How can I deal with this?
Herewith the working model:
All the plugins implement the interface IPlugin. The host start the plugin through the method in IPlugin with a new thread. The plugin begin its work as is required(this is where I want the plugin shows its form). The plugin trigger an event while the progress changed. When the task is done, the host will destroy the instance of the plugin.
thanks in advance...
modified on Sunday, May 11, 2008 10:57 AM
|
|
|
|
|
For a UI application to run in its own thread it probably needs a message pump and a UI thread.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Could you please give please give more details?
I'm not so good at messages..
Thanks.
|
|
|
|
|
I solved it in a tricky way....:
<br />
_CurrentPlugin.Window.ShowDialog(this);<br />
|
|
|
|
|
Hi all,
I'm trying to open an existing Excel file using Excel, from my C# application.
I've managed doing so using the following code:
Excel.Application excelApp = new Excel.Application();<br />
Excel.Workbook workBook = excelApp.Workbooks.Open(strFileName, 0,<br />
false, 5, "", "", true, Excel.XlPlatform.xlWindows,<br />
"\t", false, false, 0, true, 1, 0);<br />
excelApp.Visible = true;
However, I'm facing the following problem: Opening the file using this code creates a new process - EXCEL.exe, which doesn't ends after closing the Excel application!
What am I doing wrong?
Thanks a lot,
Eyal.
|
|
|
|
|
|
If you just want to display the file then how about:
System.Diagnostics.Process.Start(strFileName); That'll just launch the default viewer for the filename.
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
|
System Error mgs and flickering issue....
Hi Guru,
I want your help,
In my media application I get some errors saying “If you were in the middle of something, the information you were working on might be lost..” I cant trace the exact error, now it is big headache for me. I you guys know any solution for this please help me. In my application no any windows functionality j’t have Global hook (keyboard and mouse) , communication between AMX and PC using tcp/ip socket programming. And if application or PC hang (stuck) I rebooted it auto by watchdog so I am having lot of things in this proj that why..
Another problem ,..:
It is also from same application in there having some TV / DVD / VOD /AUDIO all entertainment things doing wn32 and using grabber controls which are to show the movies. So what I getting is when I close the TV it get flicker between my home page and TV grabber controls. These two are major issue for me and no any solution.
Please consider abt tht and help me.
Your corporation is appreciated!
Anushka
|
|
|
|
|
Hello everyone,
I am migrated from C++ to C#. I am reading through about C++ template class and C# generics' differences,
http://msdn.microsoft.com/en-us/library/c6cyy67b(VS.80).aspx
3 questions,
1.
"At the implementation level, the primary difference is that C# generic type substitutions are performed at runtime and generic type information is thereby preserved for instantiated objects."
"preserved for instantiated objects" means?
2.
"In C#, a generic type parameter cannot itself be a generic, although constructed types can be used as generics. C++ does allow template parameters."
"constructed types" means?
3.
What means "C# disallows this; the only language constructs allowed are those that can be deduced from the constraints."?
thanks in advance,
George
|
|
|
|
|
1) When you use a generic type and instantiate an object of a certain type, that type is JIT compiled. Say a generic string list... the list is JIT'ed and now the String list type exists, so if you instantiate a new instance of a generic string list, it does not have to be JIT'ed again, that information already exist.
2) Constructed types are those that have been JIT'ed.
3) Generic types can be constrained with the where clause so that the only types allowed are those that satisfy the constraints.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
Thanks Scott,
For 1, from your comments, I think it is also a common feature for any non-generics types -- compile to native code (JIT) only once when the type is used 1st time. The article should mentioned something special for generics?
For 2, "In C#, a generic type parameter cannot itself be a generic, although constructed types can be used as generics. C++ does allow template parameters." You mentioned "Constructed types are those that have been JIT'ed.", but what are not JITed (in your points not allowed)? I think during runtime, every type is JITed.
For 3, I do not know the differences, both C++ and C# will report compile error other than runtime error when met with some unsupported operator on a specific input parameter type, right?
regards,
George
|
|
|
|
|
George_George wrote: For 1, from your comments, I think it is also a common feature for any non-generics types -- compile to native code (JIT) only once when the type is used 1st time. The article should mentioned something special for generics?
Let's say you have the following piece of code
class Gen<T>
{
}
and then you do Gen<int> val = new Gen<int>(); . In C#, at runtime, the CLR knows that val is an instance of Gen<int> . You can check it out yourself - using reflection, you can get the generic type (Gen) of val. With templates in C++, the compiler generates a new class at the source code level, with the "expanded" code, and val will then be an instance of that autogenerated class. The fact that val is an instance of a template class is lost at runtime.
I guess the key thing to remember is that in .NET, generic type information is preserved at compile time and is available at runtime.
George_George wrote: For 2, "In C#, a generic type parameter cannot itself be a generic, although constructed types can be used as generics. C++ does allow template parameters." You mentioned "Constructed types are those that have been JIT'ed.", but what are not JITed (in your points not allowed)? I think during runtime, every type is JITed.
In the above example, Gen<int> is a constructed type - you've "constructed" a type using the generic Gen class. This[^] has a pretty good explanation for constructed types.
The statement that you mentioned means that you can't have generic generic type parameters - unlike C++, which allows template template types as template parameters.
George_George wrote: For 3, I do not know the differences, both C++ and C# will report compile error other than runtime error when met with some unsupported operator on a specific input parameter type, right?
Yes, but the way they work is different. C++, like I said before, generates a new class every time you instantiate a template class with a different type parameter. After that, it just compiles the autogenerated class as part of the source code and you'll get compile errors if the type you provided as the template parameter doesn't have the expected method/field/whatever that the template class expected.
In .NET, the generic type can be part of a different assembly from the code attempting to use it, so obviously, the C++ approach won't work. Therefore, the C# compiler forces you to declare constraints, which let the compiler know which operations are supported. The constraints are compiled into the assembly, and when somebody passes a type that doesn't satisfy the constraint, the compiler can figure that out and report a compiler error.
Hope that helps.
|
|
|
|
|
Thanks Senthil,
1.
S. Senthil Kumar wrote: The statement that you mentioned means that you can't have generic generic type parameters - unlike C++, which allows template template types as template parameters.
The following code, which use generics type as generics type type parameter can compile. Seems violates the above rule. Any comments?
using System;
using System.Collections.Generic;
class Test
{
static void Main()
{
Generic<Generic2<List<int>>> gen = new Generic<Generic2<List<int>>>();
}
}
class Generic<T>
{
List<T> list1 = new List<T>();
List<int> list2 = new List<int>();
List<Generic2<T>> gen1 = new List<Generic2<T>>();
List<Generic2<int>> gen2 = new List<Generic2<int>>();
}
class Generic2<U>
{
}
2.
S. Senthil Kumar wrote: In .NET, the generic type can be part of a different assembly from the code attempting to use it,
What does it mean? Means a genetics type defined in one assembly, but used/referred from another assembly? So, C# can do binary level (IL) reference, but C++ could only do source code level (header file) reference?
3.
"Therefore, the C# compiler forces you to declare constraints" -- we can define a generics type without defining any constraints, right?
In what situations, do we have to define constraints when define a generics type?
regards,
George
|
|
|
|
|
1. You are passing a constructed type (Generic2<List<int>>) and not the generic type itself. It's critical that you understand the difference between the two. Try compiling Generic<Generic2> . Does it compile? Can you see how that's different from your code?
George_George wrote: Means a genetics type defined in one assembly, but used/referred from another assembly? So, C# can do binary level (IL) reference, but C++ could only do source code level (header file) reference?
Yes, generic types can be used from a different assembly. Most template code in C++ is consumed as header files (STL, for example). IIRC, standard C++ has some facility to export templates, but none of the popular compilers support it, AFAIK.
George_George wrote: Therefore, the C# compiler forces you to declare constraints" -- we can define a generics type without defining any constraints, right?
In what situations, do we have to define constraints when define a generics type?
Without defining constraints, you can't call any methods/properties on the generic member/variable except those defined on System.Object (because all instances are guaranteed to be derived from System.Object). Try this code, for example
class G<T>
{
T t;
public G(T t)
{
this.t = t;
}
public void Method()
{
t.SayHello();
}
}
interface IHello
{
void SayHello();
}
class Hello : IHello
{
public void SayHello() { Console.WriteLine("Hello"); }
}
static void Main()
{
Hello h = new Hello();
G<Hello> g = new G<Hello>(h);
g.Method();
}
You'll find that this code doesn't compile. Let's say that G is defined in assembly A and the rest of the code is in assembly B. The compiler, when compiling code for assembly A, cannot figure out by itself that Method in G calls SayHello() on the generic member and therefore that the instance passed to G's constructor must have method SayHello. It therefore assumes only what it knows - that T must be derived from System.Object.
To get the code to compile, you'll have to tell the compiler that T will have to have SayHello. You can do this by specifying a constraint - in this case, I tell it that T is or is derived from the interface IHello. IHello has SayHello as an interface method, so the compiler knows that the generic member will have the method SayHello, and so the the generic class will compile fine.
class G<T> where T : IHello
{...}
Now when you construct G<Hello> , the compiler checks if Hello is/inherits from IHello and because it does, the code compiles fine.
Does that help?
|
|
|
|
|
Thanks Senthil,
1.
I think the points from the document is, we can not use open constructed type, but only can use close constructed type as type parameter to generics, right? I think I already provide the open constructed type -- List<Generic2<T>> gen1, but it could still compile.
2.
"Let's say that G is defined in assembly A and the rest of the code is in assembly B." -- I agree. But I think it does not matter whether or not G is defined in the same assembly or a different assembly, right? Why you stress the point that a different assembly?
regards,
George
|
|
|
|
|
George_George wrote: I think the points from the document is, we can not use open constructed type, but only can use close constructed type as type parameter to generics, right? I think I already provide the open constructed type -- List<generic2><t>> gen1, but it could still compile.
No, the point is that you cannot pass a generic type itself as a generic parameter. Have you heard about template template parameters in C++? You can do something like
template <typename T, template <typename> Container>
class A
{
}
You can then do A<std::string, std::vector> . Note that std::vector itself is a template class, which is why the second type parameter for A has another template keyword.
You can't do that with generics.
George_George wrote: Why you stress the point that a different assembly?
It doesn't matter - I wrote it that way to stress the fact that generic type information needs to be preserved in assemblies and won't be compiled away like in C++.
|
|
|
|
|
Thanks Senthil,
1.
I want to confirm that the answer to my question #3 is, C# is using constraints to check whether a type is supported or not, but C++ will generate the specific type to check whether the operation is supported or not, right?
2.
But from your sample below, I learned more. It seems C# compiler will check more than just the constraints, in your sample, without constraints, it will parse the invoked method to see whether it is supported, right?
http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=2548398[^]
regards,
George
|
|
|
|
|
George_George wrote: 1.
I want to confirm that the answer to my question #3 is, C# is using constraints to check whether a type is supported or not, but C++ will generate the specific type to check whether the operation is supported or not, right?
Yes, the C++ compiler compiles the expanded template as part of the normal compilation mechanism.
George_George wrote: But from your sample below, I learned more. It seems C# compiler will check more than just the constraints, in your sample, without constraints, it will parse the invoked method to see whether it is supported, right?
Well, as part of compilation, it'll know that you called SayHello on the generic member, but it has no way of knowing whether the generic member has a SayHello. That's why it needs you to constrain the list of types that can be "substituted" for the generic member.
|
|
|
|
|
Thanks Senthil,
Question answered. You are so knowledgable and patience!
regards,
George
|
|
|
|
|