Imagex progress bar
Imagex progress bar
Imagex progress bar
Imagex progress bar
Imagex progress bar
Imagex progress bar Imagex progress bar Imagex progress bar Imagex progress bar Imagex progress bar Imagex progress bar Imagex progress bar Imagex progress bar
Imagex progress bar Imagex progress bar
Imagex progress bar
Go Back  Xtreme Visual Basic Talk > > > Imagex progress bar


Reply
 
Thread Tools Display Modes
  #1  
Old 12-09-2014, 11:16 AM
denniswzp denniswzp is offline
Newcomer
 
Join Date: Dec 2014
Posts: 2
Unhappy Imagex progress bar


Hello I am new to this forum. I am a beginner with vb.net programming. Can someone help me with my program. I have made a program for imagex. You can set the path to a wim file and the name of it in a csv file. Then you can select it from an listbox and click install. My problem is that the progress bar doesn't work fine. It works but sometimes it freezes or goes too slow. Below is my code.



Quote:
Imports System.Text.RegularExpressions
Imports System.IO
Public Class Form1

Dim imagex As New Process
Dim startinfo As New ProcessStartInfo
Dim Val As Integer
Dim ReadStr As String
Dim RgEx As Regex
Dim RgEx2 As Regex
Dim Mtch As Match
Dim Mtch2 As Match
Dim path As String
Dim strlines
Dim strline
Dim strline1
Dim percentage As String
Dim numberofpct As Integer

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
CheckForIllegalCrossThreadCalls = False
Progress.ProgressBar1.Maximum = 100
Progress.ProgressBar1.Minimum = 0
Progress.ProgressBar1.Style = ProgressBarStyle.Continuous
Dim strfilename As String
' Load the file.
strfilename = "test.csv"
'Check if file exist
Dim tmpstream As StreamReader = File.OpenText(strfilename)
strlines = tmpstream.ReadToEnd().Split(Environment.NewLine)
tmpstream.Close()
strline = strlines(0).Split(";")
strline1 = strlines(1).Split(";")
ListBox1.Items.AddRange(strline)
End Sub

Private Sub Install_Click(sender As Object, e As EventArgs) Handles Install.Click
path = strline1(ListBox1.SelectedIndex)
imagex.EnableRaisingEvents = True
imagex.StartInfo.FileName = "imagex"
imagex.StartInfo.UseShellExecute = False
imagex.StartInfo.CreateNoWindow = True
imagex.StartInfo.Arguments = "/apply " + path.Trim() + " 1 C:\temp /logfile imagexlog.txt"
imagex.StartInfo.RedirectStandardOutput = True
Progress.Show()
RgEx = New Regex("\d+%")
RgEx2 = New Regex("\d+")
Timer1.Start()
Timer1.Interval = 2000
imagex.Start()

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
ReadStr = imagex.StandardOutput.ReadLine
If imagex.StandardOutput.Peek > -1 Then
Mtch = RgEx.Match(ReadStr)
If Mtch.Success Then
percentage = Mtch.Groups(0).Value
Mtch2 = RgEx2.Match(percentage)
If percentage = "100%" Then
Progress.Close()
Timer1.Stop()
End If
If Mtch2.Success Then
numberofpct = Mtch2.Groups(0).Value
Progress.ProgressBar1.Value = numberofpct
Progress.Text = ReadStr
End If
End If
End If
End Sub
End Class
Reply With Quote
  #2  
Old 12-09-2014, 01:10 PM
PlausiblyDamp's Avatar
PlausiblyDampImagex progress bar PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

One thing that instantly stands out is the line
Code:
CheckForIllegalCrossThreadCalls = False
Under windows (as in fact most other windowing systems) the UI should only be updated from the main UI thread, updating it from a background thread is generally a bad idea and can cause all sorts of problems e.g. hanging, crashing, failure to update the screen correctly. In fact the official documentation (http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx) points out that this is a bad move.

Looking at the code you posted though I can't see anything obvious that is running on a background thread although I am unsure about reading from StandardOutput as I have no idea if that is or isn't on another thread.

Personally I have always found trying to run and react to command line apps from a winforms application to be problematic.

Have you considered http://msdn.microsoft.com/en-us/libr.../jj134345.aspx - a supported API might be a lot easier to work with in the long run.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 12-11-2014, 11:56 AM
denniswzp denniswzp is offline
Newcomer
 
Join Date: Dec 2014
Posts: 2
Smile

Thanks for your reply. I have removed the line for illegal cross threading. It wasn't needed. I used that line for another process i used before in my application.

I shall try the wimgapi dll.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Imagex progress bar
Imagex progress bar
Imagex progress bar Imagex progress bar
Imagex progress bar
Imagex progress bar
Imagex progress bar Imagex progress bar Imagex progress bar Imagex progress bar Imagex progress bar Imagex progress bar Imagex progress bar
Imagex progress bar
Imagex progress bar
 
Imagex progress bar
Imagex progress bar
 
-->