07-05-17, 04:15 AM
شكرا لكم جميعا
تم المساعدة بواسطة صديق خارج المنتدى
والحل
'Current Process
Dim proc As Process = Process.GetCurrentProcess()
'All running processes with the same name
Dim procs() As Process = Process.GetProcessesByName(proc.ProcessName)
'////////////////////////////////////////////////////////////////////////////////'
'Read settings file
'Should be first line = Instances:5 , second line = DataLength:1000
Dim settings() As String = File.ReadAllLines(Path.Combine(APATH, "Settings.txt"))
'Read how many instances the user want
Dim instances As Integer = Integer.Parse(settings(0).Replace("Instances:", ""))
'Get data file length
Dim len As Integer = Integer.Parse(settings(1).Replace("DataLength:", ""))
'////////////////////////////////////////////////////////////////////////////////'
'Check if this one is the first instance
If procs.Length = 1 Then
'Open the program n times
For index = 1 To instances - 1
Process.Start(proc.ProcessName)
System.Threading.Thread.Sleep(200)
Next
ElseIf procs.Length > instances Then
MessageBox.Show("Cannot create more instances")
System.Environment.Exit(0)
End If
Dim skip As Integer = (procs.Length - 1) * (len \ instances)
'if proces.Length == instances take (len - skip) else take (len / instances)
'to make sure there is no leftover data
Dim take As Integer = If(procs.Length = instances, (len - skip), (len \ instances))
'Read the data
data = File.ReadLines(Path.Combine(APATH, "2.txt")).Skip(skip).Take(take).ToArray()
ListBox1.Items.AddRange(data)
'For debugging, Show HM instances are running & data[0] - data[max] in the title
Text = procs.Length & ":" & data(0) & ":" & data(data.Length - 1)
تم المساعدة بواسطة صديق خارج المنتدى
والحل
'Current Process
Dim proc As Process = Process.GetCurrentProcess()
'All running processes with the same name
Dim procs() As Process = Process.GetProcessesByName(proc.ProcessName)
'////////////////////////////////////////////////////////////////////////////////'
'Read settings file
'Should be first line = Instances:5 , second line = DataLength:1000
Dim settings() As String = File.ReadAllLines(Path.Combine(APATH, "Settings.txt"))
'Read how many instances the user want
Dim instances As Integer = Integer.Parse(settings(0).Replace("Instances:", ""))
'Get data file length
Dim len As Integer = Integer.Parse(settings(1).Replace("DataLength:", ""))
'////////////////////////////////////////////////////////////////////////////////'
'Check if this one is the first instance
If procs.Length = 1 Then
'Open the program n times
For index = 1 To instances - 1
Process.Start(proc.ProcessName)
System.Threading.Thread.Sleep(200)
Next
ElseIf procs.Length > instances Then
MessageBox.Show("Cannot create more instances")
System.Environment.Exit(0)
End If
Dim skip As Integer = (procs.Length - 1) * (len \ instances)
'if proces.Length == instances take (len - skip) else take (len / instances)
'to make sure there is no leftover data
Dim take As Integer = If(procs.Length = instances, (len - skip), (len \ instances))
'Read the data
data = File.ReadLines(Path.Combine(APATH, "2.txt")).Skip(skip).Take(take).ToArray()
ListBox1.Items.AddRange(data)
'For debugging, Show HM instances are running & data[0] - data[max] in the title
Text = procs.Length & ":" & data(0) & ":" & data(data.Length - 1)

