|
Hey, some suggestions about how to get help quickly and use it wisely:
1) Try it out yourself before asking.
2) Be specific, and very specific in your question. Vague questions and vague answers just waste your and our time.
3) Don't depend on others to do the job for you.
Best,
Jun
|
|
|
|
|
Hi.
I was just wondering, how many times you nice people will reply to these annoying subjects?
I know it sound hard, but there has to be a consequence at some point.
Programming is like Mathematics… you take ONE step at the time!
|
|
|
|
|
If you haven't noticed yet, and from the looks of your post history you'll have to try about a hundred more times before it sinks in, if you mention the word "Urgent" anywhere in your post, it gets you ignored or ridiculed.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi:
I would like to launch an application from C# if it is not already running -- I dont want multiple instances of the application running.
How do I check what programs are currently running on the system?
Thanks, smurfy
|
|
|
|
|
There are several ways to guarantee a single instance. Search CP for "single instance" and you'll get tons of articals and code snippets.
Best,
Jun
|
|
|
|
|
Are you talking about using a C# application to detect an instance of itself and stop a subsequent launch of itself? If so then the other reply about Single Instance.
If you're talking about using a C# application to launch another, unassociated application only if it's not running (ie: testapp1 checks for testapp2 and if it finds it doesn't launch but does launch if testapp2 isn't running) then you need to use Process.GetProcessesByName.
Example:
Process [] TestApp2Instance;
TestApp2Instance = Process.GetProcessesByName("TestApp2.exe");
Since Process is an array, if the length exceeds 0, then the TestApp2 is running so you can abort the launch, otherwise, do a Process.Start("TestApp2.EXE");
Keep in mind that if your testapp isn't registered as a system app in the Windows registry, you'll have to provide a full path to the app you want to launch.
Mike Poz
-- modified at 20:50 Monday 26th June, 2006
Realized I made an error...
|
|
|
|
|
using System;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
using System.Diagnostics;<br />
using System.Reflection;<br />
<br />
public class OneInstnace<br />
{ <br />
[STAThread]<br />
public static void Main()<br />
{<br />
Process instance = RunningInstance();<br />
if (instance == null)<br />
{<br />
Application.Run (new Form());<br />
}<br />
else<br />
{<br />
HandleRunningInstance(instance);<br />
}<br />
}<br />
public static Process RunningInstance()<br />
{<br />
Process current = Process.GetCurrentProcess();<br />
Process[] processes = Process.GetProcessesByName (current.ProcessName);<br />
<br />
foreach (Process process in processes)<br />
{<br />
if (process.Id != current.Id)<br />
{<br />
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") ==<br />
current.MainModule.FileName)<br />
{<br />
return process;<br />
}<br />
}<br />
}<br />
<br />
return null;<br />
}<br />
<br />
<br />
public static void HandleRunningInstance(Process instance)<br />
{<br />
ShowWindowAsync (instance.MainWindowHandle , WS_SHOWNORMAL);<br />
<br />
SetForegroundWindow (instance.MainWindowHandle);<br />
}<br />
<br />
[DllImport("User32.dll")] <br />
<br />
private static extern bool ShowWindowAsync(<br />
IntPtr hWnd, int cmdShow);<br />
[DllImport("User32.dll")] private static extern bool<br />
SetForegroundWindow(IntPtr hWnd);<br />
private const int WS_SHOWNORMAL = 1;<br />
}<br />
<br />
--Srini--
|
|
|
|
|
Hi all,
I want to implement double click event handling in my code. I have done in following way, but it is not working.
<br />
this.button1.DoubleClick += new System.EventHandler(this.button1_DoubleClick);<br />
<br />
<br />
private void button1_DoubleClick(object sender, EventArgs e)<br />
{<br />
MessageBox.Show("I am in Double Click");<br />
}<br />
<br />
Can anyone suggest me whats going wrong here?
Please help me.
Thanks in advance.
|
|
|
|
|
For_IT wrote: Can anyone suggest me whats going wrong here
Im afraid that my mind-reading AND my remote-debugging abilities are not working at the moment, so without details of any error message you receive I dont think I can tell you what went wrong.
You have also not mentioned which version of the framework you are programming against - but I can tell you that in v1.x the Button control did not contain a DoubleClick event (this may be different for the v2 framework but I dont have it in front of me to check).
Capturing a Double click in v1.x was done using the MouseDown event as follows
private void button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left && e.Clicks == 2)
{
MessageBox.Show("I was a double left button click");
}
}
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
-- modified at 10:58 Monday 26th June, 2006
|
|
|
|
|
Now .NET supports both "DoubleClick" and "MouseDoubleClick" events and the latter is for .NET 2.0 only. Check out this link.
Best,
Jun
|
|
|
|
|
Thank you both. This helped.
|
|
|
|
|
Hello all. I am interested in hiding a ListView Control underneath a
TabControl. The ListView Control will contain say, 5 columns. When the user
selects 1 of the tabs, I want to show the ListView and 3 columns (the other 2
will be hidden). When the user selects the other tab, I want to show the
other 2 columns of the ListView. Is there a way to do this without creating
two ListViews (1 for each Tab)? I have tried using all the Focus, Selected, and Show functionalities to the hidden ListView, but it will not appear over the
TabControl.
Thanks for the help.
|
|
|
|
|
A little unclear with what you are trying to do.
Try using the BringToFront and SendToBack Functions if you are wanting to change the z-order of the form.
|
|
|
|
|
I believe this is exactly what I am looking for. Thanks for the help.
|
|
|
|
|
Can any body help me in how to create a new project and how to add files to that in VSS using c# .... i hav added the reference and i am able to log into VSS... pls help me ...
Thanks in Advance
Akhil
|
|
|
|
|
Hi,
I tried the code listed in here:
http://www.codeproject.com/cs/database/mdbcompact_latebind.asp[^]
But I get an exception that there is already an open connection, although there isn't.
On the "objJRO.GetType().InvokeMember" line I get:
"Exception has been thrown by the target of an invocation"
The inner exception is:
"You attempted to open a database that is already opened exclusively by user 'Admin' on machine . Try again when the database is available."
How can I solve this?
Thanks,
Roee.
|
|
|
|
|
I am writing a service desk application. I have an XML file that a c# webservice accesses.
I have 2 tables inside an xml document. I can read from the xml without any problems but writing back to the file causes errors. Here is an sample of the file:
<?xml version="1.0" standalone="yes"?>
<ServiceDesk xmlns="http://tempuri.org/ServiceDeskData.xsd">
<ServiceCategory>
<category>
<id>1</id>
<type>Hardware - PC</type>
</category>
<category>
<id>2</id>
<type>Hardware - Printer / Scanner</type>
</category>
</ServiceCategory>
<ServiceRequest>
<Call>
<id>PBS00001</id>
<User>Test</User>
<Category>2</Category>
<Description>Some text</Description>
</Call>
<Call>
<id>PBS00002</id>
<User>Someone</User>
<Category>1</Category>
<Description>gbhjbgjhb</Description>
</Call>
</ServiceRequest>
</ServiceDesk>
ServiceDesk is the root element and then ServiceCategory and ServiceRequest are the tables holding the data. The problem occurs when i try to write back a Call to the Service Request Table. If i write to the ServiceRequest table it says that the item (a string array of 4) is too big, and if i write to the Call table it puts it outside the </ServiceRequest> element which breaks the schema. Could anybody give me some suggestions?
The c# code i use is:
DataSet d = new DataSet();
d.ReadXml("http://localhost/ServiceDeskWS/ServiceDeskData.xml");
String [] s = new String[4];
s[0] = assignID();
s[1] = User;
s[2] = Category;
s[3] = Description;
d.Tables["Call"].Rows.Add(s);
d.WriteXml(Server.MapPath("ServiceDeskData.xml"));
Thanks
|
|
|
|
|
Is Category a string? If it's an integer, you should use an object[] instead.
Logifusion[^]
|
|
|
|
|
It was originally a string, but thats not the problem i'm having. The problem is writing back a call.
|
|
|
|
|
Well, what I would try if I were you is make the DataRow first: DataRow dr = d.Tables["Call"].NewRow();
Then I would apply the same values but to the actual row and see where it breaks:
dr["id"] = assignID();
dr["User"] = User;
dr["Category"] = Category;
dr["Description"] = Description;
If there's a problem with the data, at least you can pinpoint the line where it happens.
Logifusion[^]
|
|
|
|
|
No problems with the data it writes it to the file, but it puts it outside the </ServiceRequest> element which breaks the xml schema.
|
|
|
|
|
Sorry, I didn't understand the original question. I guess the thing you have to look at is that when you load an XML like this into a DataSet, it will silently create extra keys and relations between nested tables. You might want to take a look at the real structure of the "Call" table in a debug window and see what columns are really there.
Logifusion[^]
|
|
|
|
|
The problem is with your schema: you have two different definitions for category. The first (in ServiceCategory) is a complexy type with a sequence of simple types, the second (in ServiceRequest) is just a single element simple type. to do this, you should give them different names (Category and CallCategory).
Or try modeling themn as classes and using the xsd tool to create the corresponding schema.
|
|
|
|
|
Fixed it. It was because i didnt define the Parent Row, added it on the end instead of nesting it.
The finished code is:
DataRow Child = d.Tables["Call"].NewRow();<br />
Child["id"] = assignID();<br />
Child["User"] = User;<br />
Child["CallCategory"] = Category;<br />
Child["Description"] = Description;<br />
Child.SetParentRow(d.Tables["ServiceRequest"].Rows[0]);<br />
d.Tables["Call"].Rows.Add(Child);<br />
d.WriteXml(Server.MapPath("ServiceDeskData.xml"));
|
|
|
|
|
This code below works.
XmlQuery xmls = new XmlQuery(SavedFilePath + file);<br />
node = xmls.SelectMultipleAttributes("/AutorunArchitect/Files/File/@*");<br />
<br />
br = 1; int b =0;<br />
ListViewItem lst = null;<br />
while (node.MoveNext())<br />
{<br />
temp[b,br-1] = node.Current.Value;<br />
<br />
if (br % 4 == 0)<br />
{<br />
b++;<br />
br=0;<br />
}<br />
<br />
br++;<br />
}<br />
<br />
for (i=0; i <2; i++)<br />
{<br />
lst = listView1.Items.Add(temp[i,0]);<br />
lst.SubItems.Add(temp[i,1]);<br />
lst.SubItems.Add(temp[i,2]); <br />
}
This is the test XML file
<AutorunArchitect> <br />
<Files><br />
<File<br />
FileName="files.exe"<br />
FileSize="123.4 KB"<br />
FilePath="C:\test\"<br />
FileDescription="Program description1."<br />
/><br />
<File<br />
FileName="files.html"<br />
FileSize="14 KB"<br />
FilePath="C:\test_backup\"<br />
FileDescription="Program description2."<br />
/><br />
</Files><br />
</AutorunArchitect>
Everything runs great, but I was just wondering is this a good aproach or is there any other way that makes the code to run faster?
Thanks.
|
|
|
|