Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6 application writes and I want to read it through dotnet asynchronusly.

Posted on 2013-11-04
6
Medium Priority
?
255 Views
Last Modified: 2013-11-06
I have an very old VB 6 application. It writes all the tracing information (hints &  messages) to a file. I have a dotnet wraper also arround this VB application.

Now I want to display this tracing info on screen through dotnet wraper. How to achieve this?

How can I read the hints & messages generated by VB application, in dot net wraper asynchronusly? Is there any best way that these both can communicate together? I don't want to read the same flat file being generated by the VB code as it can be read only after completing the writting.
0
Comment
Question by:GouthamAnand
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:hjgode
ID: 39624111
If the file is opened exclusive by the VB app, you cannot read of it before the VB app closes the file. Bad programming.

Does the VB app output any text to the console?

Do you have the code of the VB app too?
0
 

Author Comment

by:GouthamAnand
ID: 39624240
Yes, I am having the VB app code. And I am writing the code to write to standard output. But still I am not sure if I will be success in reading it from .net code.

Below 'If' condition is where the hints and messages being logged to flat file.

I am trying to write to standard output.


hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)         ' written by Goutham
    hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)       ' written by Goutham
    hConsoleErr = GetStdHandle(STD_ERROR_HANDLE)        ' written by Goutham
   
    If mbLogHints Then
   
        'iFile = stdout()
'        Open PathConcat(gConCentral.Server.FileServerRoot, "System\" & gConCentral.UID & "Hints.log") For Append As iFile
            ConsolePrint (sHint)                        ' written by Goutham
            'Print #iFile, Y2K(Now) & vbTab & sHint
           
        Close iFile
    End If
   
End Sub

'----------------------------------
'PURPOSE:   Write the string to Console. ' written by Goutham
'----------------------------------
   
Private Sub ConsolePrint(szOut As String)                           ' written by Goutham
    WriteConsole hConsoleOut, szOut, Len(szOut), vbNull, vbNull     ' written by Goutham
End Sub
0
 

Author Comment

by:GouthamAnand
ID: 39624341
Below is my .net code. WorkEngine.exe is the VB application.
below try...catch... block - 2nd 'using..' block I have written.
I haven't get any success till now.


public void DoWork123()
        {
            ProcessStartInfo start = new ProcessStartInfo();
            start.Arguments = "GOSWorkEngineApp.WorkEngine,we1,SQLREG";
           start.FileName = @"C:\Program Files\GOS\WorkEngine.exe";

            start.RedirectStandardOutput = true;
            start.RedirectStandardError = true;
            start.UseShellExecute = false;

            start.WindowStyle = ProcessWindowStyle.Hidden;
            start.CreateNoWindow = true;

            try
            {
                using (Process process = Process.Start(start))
                {
                    processId = process.Id;
                    while (!this.process.HasExited)
                    {
                        using (StreamReader reader = process.StandardOutput)
                        {
                            string result = reader.ReadToEnd();
                            Hinter.Hint.AddHint(result);
                            Console.Write(result);
                        }
                        //Thread.Sleep(1000);
                    }
                    //process.WaitForExit();
                }
            }
            catch (Exception ex)
            {
                Hinter.Hint.AddHint(ex.Message);
                ExceptionManager.Publish(ex);
            }
        }
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 16

Accepted Solution

by:
hjgode earned 2000 total points
ID: 39625031
Here is my code to capture the output of an app that writes to console and echos the read lines to the C# app console:

		void makeThumbSheet(string sFile){
			ProcessStartInfo startinfo = new ProcessStartInfo();
			startinfo.Arguments = 
				"-w 480 -h 75 -c 3 -r 4 -i -t -W -O /var/www/video \"" + sFile + "\"";
			startinfo.FileName = "/home/hgode/bin/mtn";
			startinfo.UseShellExecute=false;
			startinfo.CreateNoWindow=true;
			startinfo.LoadUserProfile=true;
			startinfo.RedirectStandardOutput=true;
			Process proc = new Process();
			proc.StartInfo=startinfo;
			Console.WriteLine("++++ creating img");
			proc.Start();

			while(!proc.StandardOutput.EndOfStream){
				string sOut = proc.StandardOutput.ReadLine();
				Console.WriteLine(sOut);
			}

			proc.Close();
		}

Open in new window


You only need to replace the process and arguments (if any).

Does your VB app echo its output to console when you start it manually in a MS-DOS console? Can you redirect the VB app output to a file using:
vbapp.exe >c:\myoutput.txt?
If both is yes, you should be able to capture the output with my above code snippet. Your VB code for console output looks like the one here http://www.angelfire.com/mi4/bvo/vb/vbconio.htm
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 39625369
You could use MSMQ to communicate between VB and .net application.VB application pushes message to MSMQ and .net application constantly listens to the queue and reads the message as it is available. Here is a link on how you can implement it.

http://jwbs-blog.blogspot.com/2009/06/using-msmq-to-communicate-between-net.html

Another approach is to write messages to the file from VB application and read the contents from .net application. Use mutex to make sure the file is accessed (write) by single application at any one point.

In VB, if you use FSO (File System Object) then you would be able to release the file as soon as the filesystem object is closed and set to nothing.
0
 

Author Closing Comment

by:GouthamAnand
ID: 39628251
Thankyou.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question