|
Hello, as you probably already know that I'm a n00b of C# and programming.
Here's what I want to make but I couldn't find any example to follow.
I want to make a windows form application, when you run the application it will launch a console/dos application with it, the windows form application will check every 60 seconds to see if the dos application is still running or not, if the dos application crashed the windows form application will relaunch the dos application, I also want to make a output box in the windows form application so whatever is displayed in the dos application will display in the windows form application's output box, and it would be nice if I can run the dos application within the windows form application, so it will save some taskbar space =^^=
Please don't tell me to go read MSDN Library, it's 2GB of files and I wouldn't even know where to start, just give me examples and tell tell me the syntax since I'm a n00b, but I'm pretty sure this isn't hard to do for you advanced C# programmers, so help a n00b out ^__^;
|
|
|
|
|
C# n00b wrote:
Please don't tell me to go read MSDN Library, it's 2GB of files and I wouldn't even know where to start
That's why it has a table of contents and a search facility.
C# n00b wrote:
just give me examples and tell tell me the syntax since I'm a n00b
And such you will always be, if you refuse to learn how to research things for yourself.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Take a look at the Process class in System.Diagnostics. You use the static method Process.Start to start a process. You can use the Process.WaitForExit to wait until it ends and launch it again if you'd like.
As far as redirecting the output of a console application, take a look at the ProcessStartInfo class that can be used as a parameter for the Start method. You can redirect standard output, input, and error from/to a console application using this class's various properties.
Process.Start will return an instance of the Process class, and if you set the ProcessStartInfo properties up, you can then use things like Process.StandardOutput as a stream to read out of.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
it would help if you can write some codes =^^=
I just started C# few days ago.
|
|
|
|
|
Have you done any programming before? You should probably start with simpler programs than this if you're new to programming. You should grab a book or look at sample programs and websites etc.
I once wrote a program to automate a console application (GPG) and I ended having to create threads to properly read the output of the program to avoid locking on reads of standard output. The threads brought on the need for syncrhonization objects. It's not the easiest task in the world.
Posting the code for all of this would probably do more harm than good if you're really wanting to learn. It would also be a pain for me to cut out the relevant sections and still give you something that compiles (since I'm guessing a snippet wouldn't do you any good).
In any event, if you post a program that launches another program and describe what's wrong with it, I'll take a look at it and get you further along.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
You can tell by reading my name that I'm a C# n00b and I haven't done any programming in the past, I heard start clean from C# would prevent you from getting bad habit, so here I am struggling through sam's teach yourself visual studio .net in 21 days =^^=
but I really want to make this program for my own personal use, it would help if you can give me more hint, so far I've only understand how to use Process.Start("dos.exe");
but I dunno how to make my program to check and see if the dos program is already started before it start the dos program, I tried to use if ... else but it give me error and say you can't use that in the if()
is there a way I can reach you where I can talk to you in instant msg or irc channel?
|
|
|
|
|
What did you try to put in the if statement? It sounds like you might be lacking some understanding of C# syntax in general. I think it's more important to understand this type of thing than doing arbitrary tasks like running programs. I know you're excited, but you really should learn to walk before you run. If you're new to programming in general, you should start with very easy tasks to gain understanding. Something simple like "Print the first 100 multiples of 5" or some such sillyness.
In any event, for determining if a program is already running, take a look here. The first reply to the question deals with getting a list of the running processes and checking their names. In the case of that thread, he was comparing it to the currently running program, but in your case it will be whatever the name of the program you're looking for.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
i don't quite understand that one, it's a little weird, it seems like it's used for the current application that it's making, but I using the application to check an external dos application, not the current application.
also, how do you make a monitor to monitor the status of the dos application, so when the dos application crash, the windows application will relaunch it.
I know i'm not suppose to jump ahead to do things that's too hard for a beginner, but i'm in need for this little tool and there's no other program would do this, so I have to put myself in this situation and beg for hints from you X_x;
http://www.shintasoft.com
Bring you English Version Super Robot Wars games
|
|
|
|
|
Yep. I mentioned you'd want to change this in your program. These lines...
Process proc = Process.GetCurrentProcess();
Process[] procs = Process.GetProcessesByName(proc.ProcessName);
...get the current process (and store it in a variable named proc). Then the next line of code gets all of the processes running on the machine with a name that it gets from proc.ProcessName (the name of our current process). In other words, it gets all of the processes running that have the same name as the currently running process. In your case, you'd just want something like this:
Process[] procs = Process.GetProcessesByName("foo.exe");
That's assuming you're looking for a program running called "foo.exe". You'd want to change that obviously or make it a variable instead of hardcoding (for the most part, you should never "hardcode" stuff like that). The thing you'll have to make sure of most likely is there's only one instance running. If the length of the procs array is more than 1, that means more than one instance of "foo.exe" is running in this case. If there's no instances running (length is 0), then you need to start the first one.
In any event, you should have one instance of the class Process that you'll be monitoring (either the one you got from GetProcessesByName or the one you'll get when you call Process.Start). At that point, you can call Process.WaitForExit on that instance. So for instance, if you had the Process in a variable called proc, you would do something like this:
proc.WaitForExit()
That would wait until it exits. If you only want to wait a certain amount of time, you can use the version that allows you to specify how many seconds to wait for it to exit. Something like this:
bool exited = proc.WaitForExit(10000);
if (exited)
{
}
else
{
}
Of course, you probably want to wait an indefinite amount of time, so you'll want the version of WaitForExit that takes no parameters and is a void return.
Here's a quick and dirty little program that monitors for calculator and launches one if it's not working. It's fairly self explanatory, but let me know what doesn't make sense in this example:
using System.IO;
using System.Diagnostics;
class BS
{
static void Main()
{
foreach (Process p in Process.GetProcesses())
{
System.Console.WriteLine("Found process:{0}", p.ProcessName);
}
Process ourProc;
Process[] procs = Process.GetProcessesByName("calc");
if (procs.Length == 0)
{
System.Console.WriteLine("An instance of calc.exe was not running, launching one...");
ourProc = Process.Start("calc.exe");
}
else if (procs.Length == 1)
{
System.Console.WriteLine("Found an instance of calc.exe to monitor.");
ourProc = procs[0];
}
else
{
System.Console.WriteLine("Don't know which calc.exe to monitor...");
return;
}
while (true)
{
ourProc.WaitForExit();
ourProc = Process.Start("calc.exe");
}
}
}
I tested this on Longhorn, but I'm sure it will work on every OS that .NET runs on...
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbin
|
|
|
|
|
Hello,
Does anyone know if there is any way to add a condition to your setup project so that the user can choose if they want a desktop shortcut or a program menu by selecting a checkbox. I know that you can use conditions on files, but I can't get it to work with shortcuts. I tried to apply the condition to the folders instead of the shortcuts themselves, but the setup program doesn't seem to care. It just ignores if the checkboxes are checked or unchecked. Is there another way to do this? I don't want to force desktop shortcuts or program menu groups upon the user.
Thanks,
Blake
|
|
|
|
|
Not with VS.NET's Windows Installer project designer. It provides very little exposure for the tables that make up an installer database.
Typically - in a real Windows Installer editor (Wise, InstallShield, Microsoft's Orca, etc.) - the shortcut should be associated with the component that contains the executable (which should be the key file). In some cases, developers put the shortcut in a different component and add a condition to it. If your app only installs a couple shortcuts and you want one option that determines if they are installed or not, you can have a dialog control (checkbox, for example) that sets a property that is used in the InstallExecuteSequence table for the Condition field.
In either case, though, VS.NET won't let you do it. You can download the Windows Installer SDK (part of the Platform SDK) from MSDN and use the Orca utility (the MSI is downloaded, but you have to install it manually for some strange reason) to edit the tables manually after the MSI is compiled.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I need to display an Image in a datagrid en windows forms, someone knows an easy way to do it? I had tried with some "EasyDatagrids" but I have to pay for that, some knows how to draw an image in a Datagrid?
thanks in advance
Pato
|
|
|
|
|
What if you put a placeholder in a column, impliment and OnInit method, and insert the image there ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
An Image or something? do you have and example?
|
|
|
|
|
There is an Image class in ASP.NET, I presume that WinForms has a similar class. So look it up in the MSDN, and check out how to create one dynamically.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hello,
I want to create a setup program to deploy my application, but I'm a little confused on what I need to install on the user's computer in order for my application to work. I have implemented the boot strap sample from Microsoft's website in order to install the .Net framework, but I don't know for sure what to do to make sure that my application will be able to read data from an Access database.
At first I thought that I could just use a MDAC merge module in my .msi project, but then I read that MDAC doesn't include Microsoft Jet, which is what I am using to access the database. So, should I use a JET merge module in my project instead? Or will one of the pre-existing merge modules that ship with .Net work? I saw a database_access.msm and a database_access_enu.msm already included with .Net. Would one of these merge modules do what I need?
I'll take any suggestions. Thanks!
Blake
|
|
|
|
|
Those assemblies are for the Crystal Reports .NET runtime.
You can make your own merge module that just runs the installation (there's documentation included with the Jet download that details the setup switches) as a custom action, but VS.NET's MSI project designer doesn't give you very much flexibility.
I did create one for Jet 3.5 a while back which is available on InstallSite at http://www.installsite.org/pages/en/msi/msm.htm[^]. The page also states that InstallShield created a Jet 4.0 MSM and that you can download it from their web site.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the reply. I'm still a little confused though. Here's a little more information.
My program needs to be able to open an access database and read data from it. The connection string that I am using for the dataconnection is "@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=EngSpanGlossary.mdb". I don't really understand how everything works, but I assume that this means I need the Microsoft Jet OLEDB 4.0 to be installed on the computer for my program to work.
So, will downloading the merge module from installshield and adding it to my setup project be sufficient for my application to run on other computers? Do I need the MDAC at all?
Thanks so much for your help.
Blake
|
|
|
|
|
Yes, .NET requires MDAC 2.6 or higher for ADO.NET (2.7 recommended). What you're using is the OLE DB driver for Jet databases, so OLE DB (part of ADO) is still required.
Just include the Jet MSM and the MDAC MSM (mdac27refresh is good) in the setup project and you're good to go. It will prompt for a redirection target, so just specify the [SystemFolder] (\windows\system32).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi everyone,
I have a question regarding use of Excel 2000 through C#. I have an ASP.NET page that has a datagrid control. What I would like to do is use Excel on the server side (no client interface). I would basically like to use the Excel object for printing and adding some custom headers and footers. However, I have never used any MS office product on the server side. Can someone please tell me where to start researching about this? I tried MSDN and some links I found. I could not get any comprehensive information though. Most of them deal with using Excel on the client side.
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
The Excel COM class is the same on client and server side:
//import Excel namespace
using Excel;
//...
//create invisible Excel instance
Excel.Application excel = new Excel.ApplicationClass();
//open workbook
Excel.Workbook workbook = excel.Workbooks.Open(name, Missing.Value,..., Excel.XlCorruptLoad.xlNormalLoad);
//find sheet
Excel.Sheets worksheets = workbook.Worksheets;
Excel.Worksheet sheet1 = (Excel.Worksheet)worksheets.get_Item(1);
//do something
//...
excel.Quit();
|
|
|
|
|
Hi,
Thanks for the reply I will give this a shot.
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Hi again,
Thanks for the reply. I was able to get it to work.
I have one more small question. Is it possible to pass a datagrid to an excel object to render?
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Hi,
I have a situation where I need a focus event that is raised when a change in focus takes place on a user control.
Sounds simple, but this event needs to provide a reference to the control which is losing/lost focus and the control which is gaining focus. Does any one know if there is any easy way to achieve this using the events provided in the framework? I am trying to do this whilst avoiding deriving a custom control class for each of the controls thata ppear on my user control.
On a similar note, does anyone know if its possible for a button control to be overriden to prevent it from receiving focus (even temporarily)?
Thanks in advance
Rich
|
|
|
|
|
As with most control events in Windows Forms, the sender parameter is the control that raised the event:
public class MyControl : UserControl
{
public MyControl()
{
InitializeComponents();
foreach (Control c in this.Controls)
c.GotFocus += new EventHandler(this.Control_GotFocus);
}
private void Control_GotFocus(object sender, EventArgs e)
{
Control c = sender as Control;
DoSomething(c);
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|