|
|
i created new Classlibary which will be used in my form project
i created a new public method which looks like this/
public delegate void MethodDEL(object obj);
public static void Start(string Method,string Parameter)
{
MethodDEL MM = new MethodDEL(Method);
Thread th = new Thread(new ParameterizedThreadStart(MM));
th.Start(Parameter);
}
the type string (method), will be a method in the form project later.
but now in the class libary it is not reconized as a existent method.
can i take a string a convert him to method object, because the delegate dont help.
im sorry about my english
|
|
|
|
|
asafbs2004 wrote: can i take a string a convert him to method object
Not really, but you can use Reflection to get the method with that name.
|
|
|
|
|
can you show me how to use it on my code that i gave.
thnx
|
|
|
|
|
No, but I'll give some information you may be able to use, but hopefully you'll read up on Reflection yourself.
First you'll need the Type object of whatever you're trying to execute the method on.
The easy ways are:
System.Type t = typeof(MyClass) ;
and
MyClass x = new ( MyClass ) ;
System.Type t = x.GetType() ;
In some of my code I have to do it the hard way, but I won't go into that unless I need to.
Once you have an instance of the Type, you can get a reference to a method with:
System.Reflection.MethodInfo mi = t.GetMember ( methodname ) ;
(There are overloads and a number of other things you may need in the future.)
Then execute it:
mi.Invoke ( null , System.Type.EmptyTypes ) ;
The null is used for static methods , EmptyTypes is handy for methods that don't take parameters.
|
|
|
|
|
how can i use this if the classlibary dont reconized my method.
like i said the method will be created when i create the form and add the dll that created from classlibary..
i had read about reflection, but i kind of lost the way for use this in this commnad:
string method = "BeEXE";
Thread th = new Thread(new ParameterizedThreadStart(method));
|
|
|
|
|
Well, you're probably not explaining the situation very well.
If the method exists, but all you have is the name, then Reflection should work.
If you have the code in a string and want to compile it on the fly, and then run it, that can be done, but I've never done it.
If the method doesn't exist, then there is no way to call it.
|
|
|
|
|
|
OK, I've given this more thought.
Your form will define a method that matches the MethodDEL delegate?
And you then want to pass that method to this method for execution?
A) I see little point in this method, the form can simply create and start the thread itself.
B) Don't pass the name of the method, pass the delegate, that's what delegates are for.
C) If you really want to pass the name of the method to execute, you'll also need to pass a reference to the form.
|
|
|
|
|
i have a little bit problem understand english.
only code will helps me understand the idea.
i have thinking about delegate and i try to do this:
public delegate void MethodDEL(object obj);
public static void Start(string Parameter)
{
Thread th = new Thread(new ParameterizedThreadStart(MethodDEL));
th.Start(Parameter);
}
still the same debug error of variable.
i need a type like string to be a type like a method for the thread.
the type of the MethodDEL is deleagate and not method.
if i do:
<pre>
MethodDEL DEL= new MethodDEL(Method);
i will get the same debug error of variable
|
|
|
|
|
OK, here's a method:
public static class Runner
{
public static void
RunThis
(
System.Threading.ParameterizedThreadStart What
,
object Parameter
)
{
(new System.Threading.Thread ( What )).Start ( Parameter ) ;
}
}
But, as you can see, all it does is wrap one statement, so it's hardly worth the trouble.
Here's a method it can execute (yours won't be static):
private static void
Hello
(
object Who
)
{
System.Console.WriteLine ( "Hello, {0}!" , Who ) ;
}
Executing it is as simple as:
RunThis ( new System.Threading.ParameterizedThreadStart ( Hello ) , "world" ) ;
or
(new System.Threading.Thread ( new System.Threading.ParameterizedThreadStart ( Hello ) )).Start ( "world" ) ;
I hope you can see that the RunThis method doesn't reduce the complexity of the calling method very much.
But hold on, I'll go work on a non-static version...
|
|
|
|
|
OK, here's a version of Hello that isn't static, it uses the same RunThis method as my earlier post:
public class MyClass
{
private string greeting = "Hello" ;
private string who = "world" ;
private void
Hello
(
object Who
)
{
System.Console.WriteLine ( "{0}, {1}!" , greeting , Who ) ;
}
public void
SayHello
(
)
{
RunThis ( new System.Threading.ParameterizedThreadStart ( Hello ) , who ) ;
}
}
Again, the RunThis method doesn't add much to the design, but it should do what you need.
|
|
|
|
|
thnx,
but it is a little problem..
in your example there is a method named "hello".
in my classlibary that i will create DLL later from him, the method "hello" not existent.
i will try to explain.
i want to create dll. that open new thread of unknown method, or in other words, start new thread by dynamic method.
the dll that i will create i will add him to the reference on new windows application.
than,between all methods i will choose in the form to create a new thread, from the dll that i created.
but!, i can't compiled the classlibary, because, the method isnt existent there. he existent in the windows application. the class dont know the method.
in your example the method is "hello" and there in no problem to call for new thread because the threadstart see a method name (hello) and not variable(dynamic method mention as string)
i hope you understand me. thnx for the help =]
|
|
|
|
|
sorryy..it's works!!!
thnx my friend for your help!
|
|
|
|
|
|
When we change a project type from a DLL to EXE or vice versa, what exactly internally happens? How CLR know that this is executable? Is there any tag in the MSIL generated for that assembly? How to check it? What I tried, I have a DLL without Main. I compiled it and used it. Then I put Main in it and recompiled. Then I renamed Test.Dll to Test.Exe but I got this
E:\AssemblyVersioning\DotNetFunda\bin\Debug\Test.exe is not a valid Win32 application.
I want to know the internals of EXE and DLL.
Jayant D. Kulkarni
|
|
|
|
|
|
An EXE is a specially packaged file that contains information on how to start running the code in the file in a Windows process. A DLL only contains code, not all the housekeeping information. A program called a linker is used to link OS related housekeeping code into the EXE file to make it executable.
Semicolons. the number one seller of ostomy bags world wide. - dan neely
|
|
|
|
|
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Configuration.Install;<br />
using Microsoft.Win32;<br />
using System.Reflection;<br />
using System.IO;<br />
using System.Diagnostics;<br />
using System.Windows.Forms;<br />
<br />
namespace WindowsControlLibrary1<br />
{<br />
[RunInstaller(true)]<br />
public partial class CustomInstaller : Installer<br />
{<br />
public CustomInstaller()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
protected override void OnAfterInstall(System.Collections.IDictionary savedState)<br />
{<br />
string programName = "\"" + CeAppMgrExe + "\"";<br />
string programArg = "\"" + IniFilePath + "\"";<br />
<br />
MessageBox.Show(programName + " " + programArg);<br />
Process.Start(programName, programArg);<br />
base.OnAfterInstall(savedState);<br />
}<br />
<br />
const string _ceAppMgRegistryPath = @"software\Microsoft\Windows\CurrentVersion\App Paths\CEAppMgr.exe";<br />
const string _iniFileName = "PDARAM.ini";<br />
const string _filePrefix = @"file:\";<br />
string CeAppMgrExe<br />
{<br />
get<br />
{<br />
RegistryKey subKey = null;<br />
string exePath = null;<br />
try<br />
{<br />
subKey = Registry.LocalMachine.OpenSubKey(_ceAppMgRegistryPath);<br />
exePath = (string) subKey.GetValue("");<br />
}<br />
finally<br />
{<br />
if (subKey != null)<br />
subKey.Close();<br />
}<br />
return exePath;<br />
<br />
}<br />
}<br />
string IniFilePath<br />
{<br />
get<br />
{<br />
<br />
string installFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);<br />
string iniFilePath = Path.Combine(installFolder, _iniFileName);<br />
if (iniFilePath.StartsWith(_filePrefix))<br />
{<br />
<br />
int index = _filePrefix.Length;<br />
iniFilePath = iniFilePath.Substring(index);<br />
<br />
}<br />
return iniFilePath;<br />
<br />
}<br />
}<br />
}<br />
}<br />
Can anyonehelp me? I am buliding the Desktop installer, and it starts the install proccess, but tells me there is an error in my setup file?
<b>This is my INI file</b>
[CEAppManager]<br />
Version = 1.0<br />
Componet = DeviceApplication1<br />
<br />
[DeviceApplication1]<br />
Description = PDA RAM Data Collection Application<br />
CabFiles = SmartDeviceCab1.CAB<br />
Computer Programmer Web/Mobile .NET
|
|
|
|
|
Situation:
There is a page where left side has a menu which is static and right side has screens according to the menu selected. If I change something on the page and without saving the content I click on the other menu.
Requirment:
A popup should popup- "Do you want to save the content of the page", before it redirects to the page of the menu selected.
Conditions:
If I have saved the changes then,if I click on some other menu, the message should not popup.
If I save the changes made then again I change something on that page, then, the message should popup.
|
|
|
|
|
Does 'redirect' mean this is an ASP.NET question?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I think you need to be more specific to get an answer to this question. What is it that you want help with?
|
|
|
|
|
Hello everyone,
When we invoke Set/Reset/WaitOne method on an object instance of ManualResetEvent, do we need to make it thread safe? i.e. make sure only one thread is invoking Set/Reset/WaitOne by some synchronization approach, like lock or Monitor?
thanks in advance,
George
|
|
|
|
|
When WaitOne() is called by multiple threads, it will be placed in a queue. When ManualResetEvent 's Set() is called it will signal all the threads waiting in the queue. If you want to signal only one thread in the WaitOne() queue, you need to use AutoresetEvent instead.
|
|
|
|
|
Thanks N a v a n e e t h,
I think I have not made myself understood in my original question. My question is, when we invoke methods in ManualResetEvent, like Set/Reset/WaitOne, whether we need to synchronize the function call?
Here is some code to show my question, whether we need to write code like this?
lock (_SomeManualResetEventInstanceLock)
{
_SomeManualResetEventInstance.Set();
}
lock (_SomeManualResetEventInstanceLock)
{
_SomeManualResetEventInstance.Reset();
}
lock (_SomeManualResetEventInstanceLock)
{
_SomeManualResetEventInstance.WaitOne();
}
regards,
George
|
|
|
|