|
Ok, I thought people would understand that since it is a windows form application, that i would not want it to seize up with a Thread.sleep.
My mistake.
Thanks for the response.
|
|
|
|
|
Oh, ok.
Then you can not do what you want with a single thread: use a BackgroundWorker to run your function.
|
|
|
|
|
Will that work with an ActiveX com object? Because i tried to do A separate thread for the loop and the webbrowser control on my app broke.
|
|
|
|
|
I've used a BackgroundWorker in an ActiveX object written in C# and loaded in a WebBrowser control before, and it worked.
You have obviously to make sure to use Invoke when updating the UI in your separate threads, though.
|
|
|
|
|
|
Hi,
if you only want the one thread, you should use a Windows.Forms.Timer and put your stuff in its Tick handler. It would tick every second, and your code should be done in much less, otherwise you ruin the user experience and really need a second thread (as in a BackgroundWorker).
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Well if i went the timer route, wouldn't i need a timer for each function? Ideally i want to use a timer, but i just cant figure a way on how to do it. There might be 10 or more function calls within my Loop function. Is there a more simple approach to using the timer?
Just to reiterate, my Loop function would look somthing like this:
Loop()
{
One();
Two();
Three()
...
up to 10 or more function calls.
}
The goal is to have about a 1 second wait inbetween each call
Ex:
Loop()
{
One();
Wait 1 second
Two();
...and so on
}
Thanks!
|
|
|
|
|
Hi,
you can't control time if you refuse to use threads, sleeps and timers.
IMO the easiest way is using a timer, and an counter, say (pseudo-code):
timertickHandler() {
switch(counter) {
case 0: One();
case 1: Two();
...
}
counter=(counter+1)%MAXCOUNT;
}
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
|
Can you try using ThreadPool.QueueUserWorkItem method?
Main Loop method will call method one.
That method will execute code specific to it.Then it will Sleep for 1 second and then it will queue the next method two.
Loop()
{
ThreadPool.QueueUserWorkItem(new WaitCallback(one))
}
private void one(object state)
{
//Add you code here
Thread.Sleep(1000);
ThreadPool.QueueUserWorkItem(new WaitCallback(two))
}
private void two(object state)
{
//Add you code here
Thread.Sleep(1000);
ThreadPool.QueueUserWorkItem(new WaitCallback(three))
}
Thanks,
Pradnya
|
|
|
|
|
Hi Experts,
I have an application in C# where i am calling a .reg file using process class. now i want to send keystroke y first and then i need to wait for next megssage box to appear then send enter to it.
System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");
SendKeys.Send("{y}");
SendKeys.Send("{ENTER}");
now first ket strok is working fine but not the second one. Because the second window takes some time to appear. Can anybody tell me how can i wait for the window to appear first then send the enter key stroke.
Please Help
Regards,
Paramhans Dubey.
|
|
|
|
|
Why not put a #n seconds delay between the commands.
Find out the windows handle of the dialog and poll the windows collect to detect when it is present.
|
|
|
|
|
Hi,
the quick and dirty solution is by inserting a sufficiently large delay (Thread.Sleep).
the higher performance solution I typically use needs some P/Invoke to Win32 functions such as GetForegroundWindow and GetWindowText, all in a polling retry-and-sleep loop.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
By Replacing
System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");
with
System.Diagnostics.Process.Start("RegEdit.exe", "/S " + '"'.ToString() + Application.StartupPath + "\\dsnbackup.reg" + '"'.ToString());
solved my problem. /S is used for merger in silent mode.
|
|
|
|
|
Thanx anyways guys for your replies.
|
|
|
|
|
Hi,
I have two comments:
1.
What you say does not achieve "i want to send keystroke y first and then i need to wait" at all.
Make sure you ask the right question in future.
2.
There is a shorthand for '"'.ToString() , it is "\"" and you can even merge it with a previous string literal.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I have an object (InputFile) that I am able to successfully serialize to XML and deserialize back into the object through an IXmlSerializable interface.
Now I'm trying to serialize a List<inputfile> to XML. I'm using the following code:
XmlSerializer s = new XmlSerializer(typeof(List<Inputs.InputFile>));
TextWriter w = new StreamWriter("c:\\out.xml");
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
w.Serialize(w, Global.Pool.InputFiles, ns);
w.Close();
This produces the following XML:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfInputFile>
<InputFile FileName="file1.hdr" GUID="XYZ" TimeShift="0">
</InputFile>
<InputFile FileName="file2.hdr" GUID="ABC" TimeShift="0">
</InputFile>
</ArrayOfInputFile>
This looks well formed and good to me.
I use the following to deserialize:
XmlSerializer s = new XmlSerializer(typeof(Inputs.InputFile));
TextReader r = new StreamReader("c:\\out.xml");
List<Inputs.InputFile> a = (List<Inputs.InputFile>)s.Deserialize(r);
r.Close();
I get an exception on the Deserialize line:
InvalidOperationException: {"There is an error in XML document (2, 2)."}
{"<ArrayOfInputFile xmlns=''> was not expected."}
I've had no issues Serializing/Deserializing List<>s before.
Any ideas where I went wrong?
Thanks,
Aaron
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Hi,
I guess the problem comes with the namespace (or better the missing namespace). First I would try to serialize without providing a namespace (just put away the XMlSerializerNamespace). If this doesn't work, provide a namespace (e.g. http://tempuri.org)
Please let me know if this helps you.
Regards
Sebastian
|
|
|
|
|
Hi,
Thank you for the suggestions!
When I removed the namespace from the serialization the resulting ArrayOfInputFile looks like:
<ArrayOfInputFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
On Deserialization, another InvalidOperationException: {"There is an error in XML document (2, 2)."} (2,2 cooresponds to the A in ArrayOfInputFile): {"<ArrayOfInputFile xmlns=''> was not expected."}
Providing a namespace, the XML becomes:
<ArrayOfInputFile xmlns:asdf="http://www.helloworld.com/">
With identical exceptions and error messages.
Any other information I can provide?
Thanks,
Aaron
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Hi,
the second example you provided looks a bit strange. What happens if you change the xml before deserialization so that it looks like this:
<ArrayOfInputFile xmlns="http://www.helloworld.com/">
or
<asdf:ArrayOfInputFile xmlns:asdf="http://www.helloworld.com/">
|
|
|
|
|
Hello again,
If I change it to your first form I get another InvalidOperationException, but the message this time is: {"<ArrayOfInputFile xmlns='http://www.helloworld.com/'> was not expected."}
If I change to the second form I also get: {"<ArrayOfInputFile xmlns='http://www.helloworld.com/'> was not expected."}. Interestingly it doesn't include the "asdf:" at the beginning.
Should I encapsulate this list in a class and manually serialize/deserialize?
Thanks for the help so far!
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Wow, I feel stupid, the error is so simple.
On my deserialization you can see the type is Inputs.InputFile, not List<inputs.inputfile>. Changing it makes everything work!
Thanks for your help and looking at this problem.
modified 12-Jul-20 21:01pm.
|
|
|
|
|
I have been using the following code from msdn to create a slide. But how to create a chart in a slide?
const string sTemplate = "C:\\Program Files\\Microsoft Office\\Templates\\Presentation Designs\\Blends.pot";
const string sPic = "C:\\WINNT\\Soap Bubbles.bmp";
PowerPoint.Application oApp = default(PowerPoint.Application);
PowerPoint.Presentation oPres = default(PowerPoint.Presentation);
PowerPoint.Slide oSlide = default(PowerPoint.Slide);
bool bAssistantOn = false;
//Start Powerpoint and make its window visible but minimized.
oApp = new PowerPoint.Application();
oApp.Visible = Office.MsoTriState.msoCTrue;// Microsoft.Office.Core.MsoTriState.msoCTrue;
oApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized;
//Create a new presentation based on the specified template.
oPres = oApp.Presentations.Open(sTemplate, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoCTrue);
//Build Slide #1:
//Add text to the slide, change the font and insert/position a
//picture on the first slide.
oSlide = oPres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
{
oSlide.Shapes[1].TextFrame.TextRange.Text = "My Sample Presentation";
oSlide.Shapes[1].TextFrame.TextRange.Font.Name = "Comic Sans MS";
oSlide.Shapes[1].TextFrame.TextRange.Font.Size = 48;
}
oSlide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 200, 200, 200, 200);// AddPicture(sPic, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 150, 150, 500, 350);
//oSlide.Shapes[1].Table.Rows[1].Cells[1].Borders[ PowerPoint.PpBorderType.ppBorderLeft].
oSlide = null;
PowerPoint.SlideShowSettings oSettings = default(PowerPoint.SlideShowSettings);
oSettings = oPres.SlideShowSettings;
oSettings.StartingSlide = 1;
oSettings.EndingSlide = 1;
//Prevent Office Assistant from displaying alert messages.
bAssistantOn = oApp.Assistant.On;
oApp.Assistant.On = false;
//Run the slide show and wait for the slide show to end.
oSettings.Run();
while (oApp.SlideShowWindows.Count >= 1) {
System.Windows.Forms.Application.DoEvents();
}
oSettings = null;
//Reenable Office Assisant, if it was on.
if (bAssistantOn) {
oApp.Assistant.On = true;
oApp.Assistant.Visible = false;
}
//Close the presentation without saving changes and quit PowerPoint.
oPres.Saved = Microsoft.Office.Core.MsoTriState.msoCTrue;
oPres.Close();
oPres = null;
oApp.Quit();
oApp = null;
GC.Collect();
|
|
|
|
|
Can someone help me with my project on developing a IT Helpdesk?
my project includes:
- web based helpdesk for the end users.
-we have more then 1000 end users in our company.
-the helpdesk should enable users to lodge in any query or complain about having problem with their harware, eg, if the printer is not working.
-if users can not login to the system
-forgot their password or wants their password to be resetted and so on.
-they should be able to add their name, Id number, department,email address,date and time. Also there should be a column for official use only in which the IT administrator will fill in their name, the solution of the problem and the date and time it was fixed
-their should be a submit button which sends the copy of the form to the IT administrator. Then the IT administrator will have to fill in the official column and the form will be saved i the system for future refernce.
i am trying to use C# for the first time for this project.
Can someone tell me how to start with this project since this is my first project after i have joined this It department this month. i have to make it from scratch.
|
|
|
|
|
monishalata wrote: i am trying to use C# for the first time for this project.
So, let's get this right ? you're writing system which your company, which has over 1000 employees, will use to run their helpdesk ? You've never written C# code before ? Have you coded before at all ? Do you work for Telstra, or perhaps Dell ?
You should look for another job. Your boss is obviously a retard, to think that you can somehow create a workable system with no experience.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|