Process.StandardOutput.ReadLine() not "syncing" properly - c#

I've tried to read up on a few articles about this, but some of them were over my head at the moment.
I run a program that re-caches some SQL data from an external source. I call this from a WinForm application which manipulates the aforementioned data.
While the Console app is running, I lay over the controls with a panel (with a textbox on it) and try to capture the Console app's stdout into the textbox. It "works", but has some issues with repeating lines and missing lines. Reading the stream after the process ends works fine, but I'm having issues with real-time.
CODE

It worked well for me in asynchronous way. Unfortunately I'm not so familiar with .net to write code from my memory...
Upd:
Spent a couple of minutes and found the page in MSDN. Use Process.BeginOutputReadLine Method, here is the description of the function and a sample of its usage.

Related

Taking screenshots of partially hidden windows from .NET WPF applications

I am working on a program that starts several other c# WPF applications and checks wether there are errors (using .NET Automation Services / UITesting).
One of the requirements of it is to take a screenshot of the main window and to put it into a word document. I alread got it working quite fine when it´s one application at a time (using code from this site: http://www.developerfusion.com/code/4630/capture-a-screen-shot/) , but as soon as i am using parallelism (say, checking 5 applications in a parallel manner), i am running into the problem that the screenshots of the windows may be overlapped by other windows that just popped up or that are always brought to the front (e.g. splash screens). Bringing the window to the front does not really help.
There was an older similar thread not directly regarding to WPF applications, and sadly, without a clear solution: Taking screenshot of a partially hidden window in a programmatic way
Is there a way to get a "clean" screenshot, may be with the use of the windows AutomationElement instance?

Display a CLI within my GUI

I want to make a program show the console output of a running CLI program, i.e. Minecraft server. But within a gui. So buttons and stuff for configuration of the server and then a console on one side to display server side events.
To clarify. I'm not wanting someone to tell me how to talk to the server. I'm wanting help with the gui code.
There are two options I see here:
You could have the CLI visible and control its position; with a hole cut in the region of your form to fit in the CLI. This might work well without a lot of work.
Or you could make the CLI run invisibly and capture its output and also its error output and display them in a TextBox. This is a bit harder, especially if you also want to send commands. To do this you would probably use a 2nd textbox as an input area.
I have done something similar and you may want to have alook at some of my code in the answer to my own question.
The challenge in version 2 is to keep the input and output stream in synch and running.

WPF browser: how to wait till a page loads

I have a problem with WPF browser. i want to load a web page.
Wait for it load completely and then put few search inputs and then retrieve the result and put it in excel.
I am unable to do so, main program loads and completes the execution before the pagecomplete_event is loaded. The scenario is:
load a component provider website
go to the search option and search for the part number which I am reading for a EXCEL file
put the part number in the search bar and click search
download the details
repeat the steps for MANY parts
I have done this with WinForms, and it works well. The problem is calling DOEVENTS. It sometimes makes my program hang, especially if operating on a big list. So wanted to do it in WPF.
I have put the Load_Complete event, but as I mentioned, it comes to that event after the main program has finished.
I searched and got this link: How to create and use WebBrowser in background thread. But it doesn't seem to help - there seems to be no System.Windows.Deployment in WPF - I get red squiggly underline. No other solutions that I have found seem to help, either.
This was troubling me for some time, and finally found the solution. Now I'm fairly new to vb.net so this may not be the best way, but it did work. This is in vb.net, you could probably easily convert to c#.
AddHandler (webbrowser1.LoadCompleted), AddressOf WebpageLoaded
webbrowser1.Navigate("http://www.myWebsite.net/admin/")
This creates an event that triggers the WebpageLoaded sub.
I used this to wait for the page to load and then login to my account.
Here is how I did that.
Private Sub WebpageLoaded()
If webbrowser1.Url.ToString = "http://www.myWebsite.net/admin/" Then
webbrowser1.Document.GetElementById("username").ScrollIntoView(True)
webbrowser1.Document.GetElementById("username").SetAttribute("value", "myUsername")
webbrowser1.Document.GetElementById("password").SetAttribute("value", "myPassword")
End If
End Sub
I do hope this helps. You probably don't need to ScrollIntoView I just used this to see the progress as I finally got it to work.

WebRequest.GetResponse().....What happened to it?

OK I've been playing with Silverlight and ran into something interesting that I hope someone can explain. The MSDN documentation clearly states that it has a WebRequest.GetResponse() Method. I have created some code to get the latest messages from twitter. The code works fine in a console app but I get an error when its in a silverlight app. The code is exactly the same, but in my xaml.cs file, the method seems to have disappeared from the framework. Anyone know why? Here are two screen shots showing you what I mean.
Console App: http://twitpic.com/bl6cf
Silverlight: http://twitpic.com/bl6ev
Silverlight Documentation does not list GetResponse() method because, In Silverlight you can call only BeginGetResponse method.
This is because you may block the UI thread and that may block the browser. BeginGetResponse is an asynchronous method.

reload the sourcecode of a C# app on command

i have a C# application, and id like to be able to make a system, so that within the program, you can display the sourcecode of the application. easy enough so far right?
well, i need them to be able to edit that code, almost like the debug break option... then load the new code and continue without stopping the program. so my problem is, that when this app loads its several thousand lines of code, and it takes a good block of time. after its loaded, it needs to do several hundred operations before allowing user input the first time it loads. also, it has a tcp client in it, and it is very important that it does not get disconnected.
i want people to be able to edit the source, click a button, and wait a few seconds, and have the new code inserted and "rehashed" so to speak, without having to break the overall function of the application.
im looking thorough code examples where possible and an input weather this is possible or not
~ thanks
If you want to allow people to make arbitrary changes to your program, that would be very complex. However, if you want to let them change specific behavior (like rewriting a calculation algorithm) you could have a look at Microsoft.CSharp.CSharpCodeProvide as discussed here.
I don't think you can do that (change a .net app without rebuilding it) but you can have dynamic code loaded and run at any time..
Some people use plugins with Boo, people can change the plugins and these can be loaded at any time by the main app.
But I would suggest you have a look at the Ruby usage inside SilverLight..
This is something completely different, but its something I'm reading on how to start playing with Dynamic code handling: here

Categories

Resources