|
Thanks Senthil,
I have written a test case, I am using a base class type variable to point to a derived type and in the derived type, I override a method of base class.
But it seems I can get nothing in variable fields. Any ideas?
class Program
{
class Foo
{
public static int abc;
virtual public void bcd()
{
}
}
class Goo : Foo
{
override public void bcd()
{
}
}
static void Main(string[] args)
{
Foo f = new Goo();
FieldInfo[] fields = f.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
return;
}
}
regards,
George
|
|
|
|
|
George_George wrote: But it seems I can get nothing in variable fields. Any ideas?
The text in the MSDN page is for people deriving from System.Type , for whatever reason. From a user's perspective, it returns the list of fields in the class represented by the Type.
|
|
|
|
|
Thanks Senthil,
The fields only for member variables, not for functions?
regards,
George
|
|
|
|
|
GetFields returns only fields (member variables) in that type. Type.GetMethods[^] returns functions defined in that Type.
|
|
|
|
|
Thanks Senthil,
Looks like GetMembers return both methods and fields, and GetMethods/GetFields returns just method/field? So, GetMembers is more powerful.
regards,
George
|
|
|
|
|
|
I have tested it, leppie!
Looks like GetMembers is more powerful than GetFields.
regards,
George
|
|
|
|
|
S. Senthil Kumar wrote: for whatever reason.
Every single type defined derives from Type as a RuntimeType.
|
|
|
|
|
For any user defined class, does the class implicitly derives from Type?
regards,
George
|
|
|
|
|
The field abc is defined as static, but in your GetFields() call you ask it to return only instance fields.
|
|
|
|
|
Thanks Vega02,
I think the root cause is, I do not know GetFields will not return methods before.
regards,
George
|
|
|
|
|
Can any body tell me how to add new windows service
wasim khan
|
|
|
|
|
You mean to say, how to install a window service or you want to create a service?
Parwej Ahamad
R & D with IIS 5.0/6.0
|
|
|
|
|
hi i have a service that is created by my friend in VB and now i want to add it my Computer Services by C# code how will i do this
wasim khan
|
|
|
|
|
You can use the ServiceInstaller class. It's part of the BCL.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Well there are certain ways to add a service to your windows registered services.
1) You can use the InstallUtil tool that comes with the .Net Framework;Go to the Visual Studio Command prompt and there type InstallUtil Path-to-Assembly-to-be-installed-as-service
This is a manual procedure.
2) Create a new setup project using the Visual Studio Setup Wizard and then under the "File System Editor" add the output (the assembly that you want to install as service", after this go to "Custom Actions Editor", you will see four folders there, 1- Install, 2- Commit, 3- Rollback and 4- Uninstall, right click on Install and click on "Add Custom Action" from the resulting menu, under the result dialog, locate the application folder and locate the assembly of the service that you just added in Application Folder, double click on this assembly.
Now when you run the setup project, the service will be added to your windows services if everything goes well.
For both the procedures, you would need to go to windows services console and start the service manually.
Muhammad Talha
|
|
|
|
|
thanx for ur breif Answere i think that will help me
wasim khan
|
|
|
|
|
Talha can u tell me about how can i add service using C# code
and thnax for ur first replay it really work
wasim khan
|
|
|
|
|
Well I also looked a sample on Code Project for this which calls the InstallUtil utility through code, I guess if you search this site for Dynamic Windows Service Installer, you will come across that....
anyway the code is as:
<br />
using System;<br />
using System.Diagnostics;<br />
using System.Net;<br />
using System.IO;<br />
<br />
namespace ServiceInstaller<br />
{<br />
public enum WindowsServiceAccountType<br />
{<br />
LocalService,<br />
NetworkService,<br />
LocalSystem,<br />
User<br />
}<br />
public class WindowsServiceInstallInfo<br />
{<br />
#region "FIELDS"<br />
<br />
private System.String _windowsServiceName;<br />
private System.String _wsDescription;<br />
private readonly string _windowsServicePath;<br />
private readonly string _windowsServiceAssemblyName;<br />
private WindowsServiceAccountType _wsAccountType;<br />
private readonly string _wsAccountUserName;<br />
private readonly string _wsAccountPassword;<br />
<br />
#endregion<br />
<br />
#region "CONSTRUCTOR"<br />
public WindowsServiceInstallInfo(string windowsServicePath, string windowsServiceAssemblyName, WindowsServiceAccountType wsAccountType)<br />
: this("", windowsServicePath, windowsServiceAssemblyName, wsAccountType) { }<br />
<br />
public WindowsServiceInstallInfo(string windowsServiceName, string windowsServicePath, string windowsServiceAssemblyName, WindowsServiceAccountType wsAccountType)<br />
: this(windowsServiceName, "", windowsServicePath, windowsServiceAssemblyName, wsAccountType) { }<br />
<br />
public WindowsServiceInstallInfo(string windowsServiceName, string description, string windowsServicePath, string windowsServiceAssemblyName, WindowsServiceAccountType wsAccountType)<br />
: this(windowsServiceName, description, windowsServicePath, windowsServiceAssemblyName, wsAccountType, "", "") { }<br />
<br />
public WindowsServiceInstallInfo(string windowsServicePath, string windowsServiceAssemblyName, string wsAccountUserName, string wsAccountPassword)<br />
: this("", windowsServicePath, windowsServiceAssemblyName, wsAccountUserName, wsAccountPassword) { }<br />
<br />
public WindowsServiceInstallInfo(string windowsServiceName, string windowsServicePath, string windowsServiceAssemblyName, string wsAccountUserName, string wsAccountPassword)<br />
: this(windowsServiceName, "", windowsServicePath, windowsServiceAssemblyName, wsAccountUserName, wsAccountPassword) { }<br />
public WindowsServiceInstallInfo(string windowsServiceName, string description, string windowsServicePath, string windowsServiceAssemblyName, string wsAccountUserName, string wsAccountPassword)<br />
: this(windowsServiceName, description, windowsServicePath, windowsServiceAssemblyName, WindowsServiceAccountType.User, wsAccountUserName, wsAccountPassword) { }<br />
<br />
private WindowsServiceInstallInfo(string windowsServiceName, string description, string windowsServicePath, string windowsServiceAssemblyName, WindowsServiceAccountType wsAccountType, string wsAccountUserName, string wsAccountPassword)<br />
{<br />
_windowsServiceName = windowsServiceName;<br />
_wsDescription = description;<br />
_windowsServicePath = windowsServicePath;<br />
_windowsServiceAssemblyName = windowsServiceAssemblyName;<br />
_wsAccountType = wsAccountType;<br />
_wsAccountUserName = wsAccountUserName;<br />
_wsAccountPassword = wsAccountPassword;<br />
<br />
if (_wsAccountType == WindowsServiceAccountType.User && _wsAccountUserName == "")<br />
{<br />
throw new Exception("Username must be provided if AccountType to start the Windows Service is USER");<br />
}<br />
}<br />
#endregion<br />
<br />
#region "PROPERTIES"<br />
public System.String WindowsServiceName<br />
{<br />
get<br />
{<br />
return _windowsServiceName;<br />
}<br />
set<br />
{<br />
_windowsServiceName = value;<br />
}<br />
}<br />
public string WindowsServiceDescription<br />
{<br />
get<br />
{<br />
return _wsDescription;<br />
}<br />
set<br />
{<br />
_wsDescription = value;<br />
}<br />
}<br />
public string WindowsServicePath<br />
{<br />
get<br />
{<br />
return _windowsServicePath;<br />
}<br />
}<br />
public string WindowsServiceAssemblyName<br />
{<br />
get<br />
{<br />
return _windowsServiceAssemblyName;<br />
}<br />
}<br />
public WindowsServiceAccountType wsAccountType<br />
{<br />
get<br />
{<br />
return _wsAccountType;<br />
}<br />
}<br />
public string wsAccountUserName<br />
{<br />
get<br />
{<br />
return _wsAccountUserName;<br />
}<br />
}<br />
public string wsAccountPassword<br />
{<br />
get<br />
{<br />
return _wsAccountPassword;<br />
}<br />
}<br />
#endregion<br />
}<br />
<br />
public class WindowsServiceInstallUtil<br />
{<br />
public static string InstallUtilPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();<br />
<br />
protected WindowsServiceInstallInfo _wsInstallInfo;<br />
<br />
public WindowsServiceInstallUtil(WindowsServiceInstallInfo wsInstallInfo)<br />
{<br />
_wsInstallInfo = wsInstallInfo;<br />
}<br />
private static bool CallInstallUtil(string installUtilArguments)<br />
{<br />
Process proc = new Process();<br />
proc.StartInfo.FileName = Path.Combine(InstallUtilPath, "installutil.exe");<br />
proc.StartInfo.Arguments = installUtilArguments;<br />
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;<br />
proc.StartInfo.RedirectStandardOutput = true;<br />
proc.StartInfo.UseShellExecute = false;<br />
<br />
proc.Start();<br />
<br />
string outputResult = proc.StandardOutput.ReadToEnd();<br />
proc.WaitForExit();<br />
if (proc.ExitCode != 0)<br />
{<br />
return false;<br />
}<br />
return true;<br />
}<br />
public bool Install()<br />
{<br />
return Install("");<br />
}<br />
public virtual bool Install(string logFilePath)<br />
{<br />
string installUtilArguments = GenerateInstallUtilInstallArgs(logFilePath);<br />
return CallInstallUtil(installUtilArguments);<br />
}<br />
<br />
protected string GenerateInstallUtilInstallArgs(string logFilePath)<br />
{<br />
string installUtilArguments = " /account=\"" + _wsInstallInfo.wsAccountType + "\"";<br />
if (_wsInstallInfo.WindowsServiceName != "")<br />
{<br />
installUtilArguments += " /name=\"" + _wsInstallInfo.WindowsServiceName + "\"";<br />
}<br />
if (_wsInstallInfo.WindowsServiceDescription != "")<br />
{<br />
installUtilArguments += " /desc=\"" + _wsInstallInfo.WindowsServiceDescription + "\"";<br />
}<br />
if (_wsInstallInfo.wsAccountType == WindowsServiceAccountType.User)<br />
{<br />
installUtilArguments += " /user=\"" + _wsInstallInfo.wsAccountUserName + "\" /password=\"" + _wsInstallInfo.wsAccountPassword + "\"";<br />
}<br />
<br />
installUtilArguments += " \"" + Path.Combine(_wsInstallInfo.WindowsServicePath, _wsInstallInfo.WindowsServiceAssemblyName) + "\"";<br />
<br />
if (logFilePath.Trim() != "")<br />
{<br />
installUtilArguments += " /LogFile=\"" + logFilePath + "\"";<br />
}<br />
<br />
return installUtilArguments;<br />
}<br />
<br />
public bool UnInstall()<br />
{<br />
return UnInstall("");<br />
}<br />
<br />
public virtual bool UnInstall(string logFilePath)<br />
{<br />
string installUtilArguments = GenerateIntallUtilUnInstallArgs(logFilePath);<br />
return CallInstallUtil(installUtilArguments);<br />
}<br />
<br />
protected string GenerateIntallUtilUnInstallArgs(string logFilePath)<br />
{<br />
string installUtilArgs = " /u ";<br />
if (_wsInstallInfo.WindowsServiceName != "")<br />
{<br />
installUtilArgs += " /name=\"" + _wsInstallInfo.WindowsServiceName + "\"";<br />
}<br />
installUtilArgs += " \"" + Path.Combine(_wsInstallInfo.WindowsServicePath, _wsInstallInfo.WindowsServiceAssemblyName)+"\"";<br />
if (logFilePath.Trim() != "")<br />
{<br />
installUtilArgs += " /LogFile=\"" + logFilePath + "\"";<br />
}<br />
return installUtilArgs;<br />
}<br />
}<br />
}<br />
let me know if you need further assisstance.
Muhammad Talha
|
|
|
|
|
thnax Talha i think that is enough for me
wasim khan
|
|
|
|
|
hi !
i have two project in one solution , form1 from project 1 is running and i m calling from this to prject2 form 2 like that
project2.form2 f = new project2.form2();
f.show();
on the buton of form1 call this and form is opening succesfully but when i closed the form2 then its back to form 1 , becouse form 1 is already opend then my question is that which event is fire when i got back to form1 , i checked Activated event is not working may b cumming from other project , may what is differnce b/w show and showdailogue() , when i call like f.showdailogue() ; then its just open and closed automatically .
Further Detail :
i have a image on form1 i move this image to form2 and edit that image and then save and when i return back to form1 then its should automatically update but its not updated , when i found the event then on that event in form1 i just reload the image to given path .
|
|
|
|
|
You should have to code on FormClosing event of form2 to notify your form1 that form2 is closed and than... on recieving notification u can reload your image.
|
|
|
|
|
yah i coded to on form closing event or form2 but still when i come to form1 then there is no difference in form1 picturebox control i coded like this on form2 closed event
project1.form1 g = new project1.form1();
g.picturebox.Image = null;
g.picturebox.Image = Image.FromFile(@"C:\Temp\Temp2.jpg");
g.picturebox.Refresh();
but after this coded still no differnce in form1 picture box , but when i came to form1 then i made here update button when i pressed it then its update on update button i coded
g.picturebox.Image = Image.FromFile(@"C:\Temp\Temp2.jpg");
g.picturebox.Refresh();
but i want its directly update and refresh image when i closed form2 and come to form1 .
|
|
|
|
|
nomi wrote: but after this coded still no differnce in form1 picture box
Yes, there is, but you can't see it. You have created a new instance of form1, in which you are changing the picture box.
If you want to change the picture box in the existing instance of form1, you need a reference to it in form2. Add a private variable of the type form1 to form2, and a parameter in the constructor of form2 of the type form1. Send a reference to form1 (Me) when you create the form2 instance, and in the constructor you store that in the private variable.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
please tell me the code becouse i m new in c#
|
|
|
|
|