|
You can use switch statements to handle lots of if/else logic:
string s = "foo";
switch(s)
{
case "bar":
Console.WriteLine("It was bar!");
break;
case "foo":
Console.WriteLine("It was foo!");
break;
case "baz":
Console.WriteLine("It was baz!");
break;
}
|
|
|
|
|
Hi all,
I am creating an application to control the execution over the remote machines using STAF tool.
Well at the moment i can start the exe over remote machine but i want to now control it like pause, continue and all. So below piece of code is in JAVA. could any one help me out in converting it to C#.NET. Well i have recieved no help from googles for STAF(Software Testing Automation Framework). So if any one could help me out in this then it woould be gr8.
Thanks a lot
if you click on the "Pause" button, the application will Pause. If you then click on the
"Continue" button, the application will resume. Let's take a look at how this code is implemented.
STAFDemoController.java
691: fPause.addActionListener(new ActionListener() {
692: public void actionPerformed(ActionEvent event)
693: {
694: STAFResult stafResult =
695: STAFDemoController.handle.submit2(
696: fMachine, "SEM", "RESET EVENT STAFDemo/Handle/" +
697: fHandle + "/Continue");
698:
699: if (stafResult.rc != 0)
700: System.out.println("Error pausing process RC: " +
701: stafResult.rc + " Result: " + stafResult.result);
702: }
703: });
On line 695 there is a call to the Semaphore service on the machine where the application is running. This call will reset the event semaphore which is uniquely identified by the application's handle.
Now let's look at how the application uses this semaphore":
STAFProcess.java
156: String continue_semaphore = new String(
157: "wait event STAFDemo/Handle/"+h+"/Continue");
196: // block if semaphore is reset, fall through if posted (or
197: // if error!!!)
198: semaphore = handle.submit2(machine, "SEM", continue_semaphore);
In STAFProcess, on line 198 there is a call to the local Semaphore service. The variable continue_semaphore is defined
on line 156.
This call to submit2 will cause application to wait for the event semaphore uniquely identified by its handle. Thus,
whenever STAFDemoController resets the event semaphore, the application will then wait for the event semaphore,
effectively pausing the application's execution.
-- modified at 9:32 Friday 13th April, 2007
|
|
|
|
|
Your post doesn't really have a specific question, so this will be a rather general answer.
I can tell you that you don't need ActionListener class -- while Java forces you to create a class that handles some "event" (in this case, the ActionPerformed event), C# lets you do this using events and delegates. So it would be
fPause.ActionPerformed += myActionPerformedHandlerFunction;
...
void myActionPerformedHandlerFunction(...)
{
STAFResult stafResult = ...
}
For semaphores, look at System.Threading.Semaphore[^]
You can pause any thread (and thus, the whole application) by waiting on a semaphore using the WaitOne method on the Semaphore class. The Semaphore class should work much like the semaphore used in your Java code.
|
|
|
|
|
Well what about this fPause.Act..... line
well i dont think fPause is already defined in C#.NET
I know its hard to explain the whole thing here as not much people knows about STAF and even STAF at the moment doesnt support C# so its not even relevant to ask questions in there forum.
Anyway i am trying to communicate between the two exe. At the moment i can run exe from local system to remote but i want a back communication i.e. after local to remote communication, remote exe goies back to local to ask for more info to run specific task and after recievin info it gets executed.
But as i am not getting it at the moment so i am trying to add functionality of pause, resume exe frm local system using semaphor and queue.
Anyway thanks for your reply
|
|
|
|
|
What type is the fPause variable?
For communication between 2 .NET processes, search for .NET remoting.
|
|
|
|
|
Hi guys,
I am trying to go through EACH SELECTED ITEM in a listbox and move it over with certain configuration to another listbox. I can't figure it out how to go through each and unselect it and then go through the next one.
In list view there is somethign like foreach(ListViewItem item in listbox1.SelectedItems) is there something like that for a listbox where I can go through each selected item and process and unselect and again go through the next one.
Please help.
I appreciate your help in advance.
sasa
|
|
|
|
|
Hi,
look at the properties SelectedItems, and dont forget to set SelectionMode.
|
|
|
|
|
I have done this, this is not my question.
sasa
|
|
|
|
|
Please clarify the problem, show the code you have, and tell us what exactly
is going wrong.
|
|
|
|
|
Hi Luc,
thanks for your response. All that I am trying to do is load one listview and move data from one listview to another. But when I move the data, I don't want to remove it from the first listview. To avoid duplicates int he second listview in case the user moves it once and tries again, I want to check to make sure there are no duplicates.
So, when moving from one listview to another I want to first check if it exists in the second and if not then only move.
Please advice.
sasa
|
|
|
|
|
Hi,
so you want to copy, not move.
Here is what I would try (assuming the items are just strings, if not modify where
appropriate):
ListView lvw1=new ListView();
ListView lvw2=new ListView();
...
foreach (string s1 in lvw1.SelectedItems) {
bool found=false;
foreach (string s2 in lvw2.Items) {
if (s1==s2) {
found=true;
break;
}
}
if (!found) lvw2.Items.Add(s1);
}
|
|
|
|
|
Thank you mate for your help. I used your suggestion and got it to work.
sasa
|
|
|
|
|
for showing some text on an image am using the GDI
it is doing well.
but the thing is I am not able to give some effects to it like some zoom in effect or flying effct or any thing atleast some effects.
any help is appriciated.
thanks
Ravikumar Patra
|
|
|
|
|
Either consider using DirectX, WPF (really trivial with WPF), or transformations. With transformations, you can rotate, scale, shear and so on.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
ok
using Direct X how it can be done
plz help me
Ravikumar Patra
|
|
|
|
|
Asalam o Alaikum:
i want to get coloumns count from listview using SendMessage() Api function.
can anybody tell me about this.
Thanx
|
|
|
|
|
Have you missed the right forum, haven't you?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
how this is a wrong forum tell me???????
|
|
|
|
|
Because the ListView (of Windows Forms) has the Columns.Count property, i.e. there's no need to use SendMessage API function.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
you are right but what about the situation when you are retrieving data from one application to other.
we have to use SendMessage() there.
|
|
|
|
|
I have a multi threaded app, it has [STAThread] on the static void main, but all of a sudden ( and I don't see why ), it's giving me an error telling me that I should be running STA, when another thread loads files from the hard drive. I am using the backgroundworker class, and I can't work out how to make it run as STA, is this possible, or am I hosed ?
Thanks
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I don't believe that you can get the BackgroundWorkerThread to run STA, as it would go against the purpose for which it was created. What error are you getting?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
current thread must be set to single thread apartment (STA) mode before OLE calls can be made
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
There's no way that you can force the BackgroundWorker ApartmentState to STA. You're either going to have to use threading with the appropriate ApartmentState set or a version of the BackgroundWorker[^] class included here.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Cool - thank you
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|