I have a Form with two ListBoxes on them. I have removeFromBoxWaiting that watches for creating of new files in a directory.
Once a file is created it prints it out and then it should add the name of the file into the list box.
My problem is that the list box does not get updated. Items actually have been added but they do not show and i have tried update() as well but it didn't work. So any tips will be appreciated. Thanks in advance.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using System.Threading;
using System.Configuration;
namespace PrntToKitchen
{
public partial class PrintFiles : DevExpress.XtraBars.Ribbon.RibbonForm
{
FileSystemWatcher filesWatcher = new FileSystemWatcher();
public void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
{
MessageBox.Show(e.Item.Name);
if (Properties.Settings.Default[e.Item.Name + "Read"].ToString().Length > 1 && Properties.Settings.Default[e.Item.Name + "ExtIn"].ToString().Length > 1)
{
filesWatcher.Path = Properties.Settings.Default[e.Item.Name + "Read"].ToString();
filesWatcher.Created += new System.IO.FileSystemEventHandler(eventG);
//filesWatcher.Deleted += new System.IO.FileSystemEventHandler(addToBoxFinished);
filesWatcher.EnableRaisingEvents = true;
}
}
public void eventG(object sender, FileSystemEventArgs e)
{
string CurrentPrinter = "";
string findPrt = e.FullPath.Substring(0, e.FullPath.Length-(e.Name.Length + 1));
string findPrtExt = e.Name.Substring(e.Name.LastIndexOf("."));
for (int i = 1; i <= Properties.Settings.Default.NumberOfPrinters; i++)
{
string testPrt = Properties.Settings.Default["Printer" + i + "Read"].ToString();
string testExt = Properties.Settings.Default["Printer" + i + "ExtIn"].ToString();
if (testPrt == findPrt && testExt == findPrtExt)
{
CurrentPrinter = "Printer" + i.ToString();
POSPrinter printer = new POSPrinter(Properties.Settings.Default["Printer" + i + "Port"].ToString(), (int)Properties.Settings.Default["Printer" + i + "Speed"]);
addToBoxWaiting(e.FullPath.ToString());
string file = e.FullPath;
printer.BeginPrint();
printer.PrintFile(file);
printer.EndPrint();
printer.Dispose();
if ((bool)Properties.Settings.Default[CurrentPrinter + "Delete"])
{
IsFileLocked(file);
System.IO.File.Delete(file);
}
else
{
System.IO.File.Move(file, Properties.Settings.Default[CurrentPrinter + "Store"] + "\\" + e.Name + Properties.Settings.Default[CurrentPrinter + "ExtOut"]);
}
removeFromBoxWaiting(e.FullPath.ToString());
addToBoxFinished(e.FullPath.ToString());
busy = false;
break;
}
}
}
void addToBoxWaiting(string text)
{
listBox1.Items.Add(text);
}
void removeFromBoxWaiting(string text)
{
listBox1.Items.Remove(text);
}
public void addToBoxFinished(string destination)
{
listBox2.Items.Add(destination);
}
}
}
I believe your problem is that you are trying to add/remove listbox items while iterating through a loop (and both this actions are happening on UI thread). You should move your for loop into a separate thread, and your addToBoxWaiting method will then look like this:
private void AddToListBox(string item)
{
MethodInvoker del = delegate
{
listBox1.Items.Add(item);
};
BeginInvoke(del);
}
Edit. Added thread code.
public void eventG(object sender, FileSystemEventArgs e)
{
Thread eventThread = new Thread(ThreadProcEventG);
eventThread.Start(e);
}
private void ThreadProcEventG(object eventArgs)
{
var e = (FileSystemEventArgs)eventArgs;
string CurrentPrinter = "";
string findPrt = e.FullPath.Substring(0, e.FullPath.Length-(e.Name.Length + 1));
string findPrtExt = e.Name.Substring(e.Name.LastIndexOf("."));
for (int i = 1; i <= Properties.Settings.Default.NumberOfPrinters; i++)
{
string testPrt = Properties.Settings.Default["Printer" + i + "Read"].ToString();
string testExt = Properties.Settings.Default["Printer" + i + "ExtIn"].ToString();
if (testPrt == findPrt && testExt == findPrtExt)
{
CurrentPrinter = "Printer" + i.ToString();
POSPrinter printer = new POSPrinter(Properties.Settings.Default["Printer" + i + "Port"].ToString(), (int)Properties.Settings.Default["Printer" + i + "Speed"]);
addToBoxWaiting(e.FullPath.ToString());
string file = e.FullPath;
printer.BeginPrint();
printer.PrintFile(file);
printer.EndPrint();
printer.Dispose();
if ((bool)Properties.Settings.Default[CurrentPrinter + "Delete"])
{
IsFileLocked(file);
System.IO.File.Delete(file);
}
else
{
System.IO.File.Move(file, Properties.Settings.Default[CurrentPrinter + "Store"] + "\\" + e.Name + Properties.Settings.Default[CurrentPrinter + "ExtOut"]);
}
removeFromBoxWaiting(e.FullPath.ToString());
addToBoxFinished(e.FullPath.ToString());
busy = false;
break;
}
}
}
You may try the following code:
listBox.Dispatcher.Invoke(ew Action(()=>listBox.Item.Add(item))
Related
Okay so yes I am doing homework and I am SO close on this one I know it, but ive been messing with it for over an hour and now I'm going insane, if i take the loop out my program will read the file and say weather you passed but it wont write the wrong answers in the listbox, if i put in my foreach code it gives me a syntax error.
this is my current code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace DriversLicenseExam
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] answerArray ={"B","D","A","A","C",
"A", "B","A","C","D",
"B", "C","D","A","D",
"C", "C","B","D","A"};
string[] studentansArray = new string[20];
List<string> incorrectList = new List<string>();
int count = 0, index = 0, qnumber = 0;
try
{
string filename = "../../" + filenametxt.Text;
StreamReader inputFile = File.OpenText(filename);
while(!inputFile.EndOfStream)
{
studentansArray[index] = inputFile.ReadLine();
if (studentansArray[index] == answerArray[index])
count++;
else
{
qnumber = index + 1;
incorrectList.Add(qnumber.ToString());
}
index++;
}
inputFile.Close();
if (count >= 15)
{
resultoutput.Text = "You Passed The Test!";
}
else
resultoutput.Text = "You Failed The Test... You're a Failure!";
}
foreach (string str in incorrectList) // <<-- error is here
{
lbox.Items.Add(str);
} // <<-- error is here
catch (Exception)
{
MessageBox.Show("File Not Found");
}
}
private void button2_Click(object sender, EventArgs e)
{
filenametxt.Text = "";
resultoutput.Text = "";
lbox.Items.Clear();
}
private void exitbutton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
I'm not 100% sure about this, but your foreach is between your try and catch block, maybe try with that:
try
{
string filename = "../../" + filenametxt.Text;
StreamReader inputFile = File.OpenText(filename);
while(!inputFile.EndOfStream)
{
studentansArray[index] = inputFile.ReadLine();
if (studentansArray[index] == answerArray[index])
count++;
else
{
qnumber = index + 1;
incorrectList.Add(qnumber.ToString());
}
index++;
}
inputFile.Close();
if (count >= 15)
{
resultoutput.Text = "You Passed The Test!";
}
else
resultoutput.Text = "You Failed The Test... You're a Failure!";
foreach (string str in incorrectList)
{
lbox.Items.Add(str);
}
}
catch (Exception)
{
MessageBox.Show("File Not Found");
}
I have a function that gets the running apps every 10 seconds, place them on a listbox and sends them to the other window if you click the send button. Now the problem is whenever I try to open then immediately close an app, it would send an error pointing to my list.
I'm not sure what to do here.
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index.
Here's my code if in case it brings any help:
private List<int> listedProcesses = new List<int>();
private void SendData()
{
String processID = "";
String processName = "";
String processFileName = "";
String processPath = "";
string hostName = System.Net.Dns.GetHostName();
listBox1.BeginUpdate();
try
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
piis = GetAllProcessInfos();
try
{
if (!listedProcesses.Contains(piis[i].Id)) //place this on a list to avoid redundancy
{
listedProcesses.Add(piis[i].Id);
processID = piis[i].Id.ToString();
processName = piis[i].Name.ToString();
processFileName = piis[i].FileName.ToString();
processPath = piis[i].Path.ToString();
output.Text += "\n\nSENT DATA : \n\t" + processID + "\n\t" + processName + "\n\t" + processFileName + "\n\t" + processPath + "\n";
}
}
catch (Exception ex)
{
wait.Abort();
output.Text += "Error..... " + ex.StackTrace;
}
NetworkStream ns = tcpclnt.GetStream();
String data = "";
data = "--++" + " " + processID + " " + processPath + " " + processFileName + " " + hostName;
if (ns.CanWrite)
{
byte[] bf = new ASCIIEncoding().GetBytes(data);
ns.Write(bf, 0, bf.Length);
ns.Flush();
}
}
}
finally
{
listBox1.EndUpdate();
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ProcessInfoItem pii = piis.FirstOrDefault(x => x.Id == (int)(sender as ListBox).SelectedValue); //setting value for list box
if (pii != null)
{
string hostName = System.Net.Dns.GetHostName();
textBox4.Text = listBox1.SelectedValue.ToString();
textBox5.Text = (pii.FileName);
textBox6.Text = (pii.Path);
textBox7.Text = hostName;
}
}
private List<ProcessInfoItem> piis = new List<ProcessInfoItem>();
private void Form1_Load(object sender, EventArgs e)
{
piis = GetAllProcessInfos();
listBox1.DisplayMember = "Name";
listBox1.ValueMember = "Id";
listBox1.DataSource = piis;
textBox1.Text = GetIpAdd().ToString();
}
private List<ProcessInfoItem> GetAllProcessInfos()
{
List<ProcessInfoItem> result = new List<ProcessInfoItem>();
Process currentProcess = Process.GetCurrentProcess();
Process[] processes = Process.GetProcesses();
foreach (Process p in processes)
{
if (!String.IsNullOrEmpty(p.MainWindowTitle))
{
ProcessInfoItem pii = new ProcessInfoItem(p.Id,p.MainModule.ModuleName, p.MainWindowTitle, p.MainModule.FileName);
result.Add(pii);
}
}
return result;
}
public class ProcessInfoItem
{
public int Id { get; set; }
public string Name { get; set; }
public string FileName { get; set; }
public string Path { get; set; }
public ProcessInfoItem(int id, string name, string filename, string path)
{
this.Id = id;
this.Name = name;
this.FileName = filename;
this.Path = path;
}
}
You are indexing over a different collection that your for loop is referencing. It sounds like you may want:
piis = GetAllProcessInfos();
for (int i = 0; i < piis.Count; i++)
{
instead. However you are calling that function form within the for loop so it's not clear what you should be iterating over.
try to change,
for (int i = 0; i < listBox1.Items.Count; i++)
{
piis = GetAllProcessInfos();
to
piis = GetAllProcessInfos();
for (int i = 0; i < piis.Count; i++)
{
Env: C#, VStudio 2013, 4.5 Framework, Winforms
Goal : Insert, inside a Treeview, the content of a folder (Sub folder + files) so that user can select those needed. Display a progressbar that show the progress of loading the files and folders in the TreeView.
What i've done so far : Everything in my goal but ...
Error: "This BackgroundWorker is currently busy and cannot run multiple tasks concurrently". I get this error sometimes when I go use other apps while my application is running.
My code :
void backgroundWorkerTreeView_DoWork(object sender, DoWorkEventArgs e)
{
var progress = (((float)(int)e.Argument / (float)totalFilesInTN) * 100);
var value = (int)Math.Round((float)progress);
backgroundWorkerTreeView.ReportProgress(value, e.Argument.ToString());
}
void backgroundWorkerTreeView_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
stStripBarMain.Value = e.ProgressPercentage;
toolStripStatusLabelPrct.Text = " Loading " + e.UserState + " of " + totalFilesInTN;
}
void backgroundWorkerTreeView_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//do the code when bgv completes its work
}
private void ListDirectory(TreeView treeView, string path)
{
try
{
treeView.Nodes.Clear();
if (path != "")
{
var rootDirectoryInfo = new DirectoryInfo(path);
treeView.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo, 0));
}
}
catch (Exception e)
{
txtLog.Text = txtLog.Text + "[" + DateTime.Now + "] " + e.Message + "\r\n";
}
}
private TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo, int indice)
{
var directoryNode = new TreeNode(directoryInfo.Name);
foreach (var directory in directoryInfo.GetDirectories())
{
if ((directory.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
directoryNode.Nodes.Add(CreateDirectoryNode(directory, indice));
}
}
foreach (var file in directoryInfo.GetFiles())
{
if ((IsNullOrEmpty(ext)) ||
(Array.IndexOf(ext, Path.GetExtension(file.Name.ToLowerInvariant())) >= 0))
{
if ((GetTriggerEvent(file.FullName).Contains(txtParamEvent.Text)) || (txtParamEvent.Text == ""))
{
indice++;
backgroundWorkerTreeView.RunWorkerAsync(indice);
TreeNode newTN = new TreeNode();
newTN.Text = file.Name + #" (" + GetTriggerEvent(file.FullName) + #")";
newTN.Name = file.FullName;
directoryNode.Nodes.Add(newTN);
newTN.Tag = "msg";
}
}
Application.DoEvents();
}
return directoryNode;
}
Thanks for the help
Richard
I have a set of questions in my database and I need to retrieve them in a random order every time.
Can someone please help me out with the C# code? I'm using Visual Studio 2012.
Thanks in advance.
Here's the code I'm using at the moment:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class perform_test : System.Web.UI.Page
{
public int CurrentPage
{
get
{
object o = this.ViewState["_CurrentPage"];
if (o == null)
return 0;
else
return (int)o;
}
set
{
this.ViewState["_CurrentPage"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write(Session["Company"]);
if (!Page.IsPostBack)
{
Session.Add("CorrectAnswers", 0);
//Session.Add("Questions", 0);
Session.Add("Answer", "");
}
if (repeat_exam_data.Controls.Count > 0)
{
for (int i = 1; i <= 4; i++)
{
RadioButton rad = repeat_exam_data.Controls[0].FindControl("Choice" + i.ToString()) as RadioButton;
if (rad.Checked)
{
Session["Answer"] = rad.Text;
break;
}
}
}
GetPage();
}
protected void GetPage()
{
DataTable exam_data = new DataTable();
exam_data = BussinessLayer.GetExamData(Session["Company"].ToString(), Session["Subject"].ToString(), Session["ExamId"].ToString());
PagedDataSource pgds = new PagedDataSource();
pgds.DataSource = exam_data.DefaultView;
pgds.AllowPaging = true;
pgds.PageSize = 1;
pgds.CurrentPageIndex = CurrentPage;
repeat_exam_data.DataSource = pgds;
repeat_exam_data.DataBind();
Cmd_Next.Enabled = !pgds.IsLastPage;
Cmd_Finish.Enabled = pgds.IsLastPage;
lblQno.Text = Convert.ToString((CurrentPage + 1));
lblCorrectAnswers.Text = Session["CorrectAnswers"].ToString();
}
protected void Cmd_Next_Click(object sender, EventArgs e)
{
CalculateMark();
CurrentPage += 1;
GetPage();
}
protected void Cmd_Finish_Click(object sender, EventArgs e)
{
CalculateMark();
string strSql = "INSERT INTO tbl_result(ExamId,StudentId,Mark) VALUES('" + Session["ExamId"] + "','" + Session["uname"] + "','" + Session["CorrectAnswers"] + "')";
BussinessLayer.PutData(strSql);
Response.Redirect("~/canexamresult.aspx");
}
private void CalculateMark()
{
HiddenField ans = repeat_exam_data.Controls[0].FindControl("Answer") as HiddenField;
if (Session["Answer"].ToString() == ans.Value)
Session["CorrectAnswers"] = (int)Session["CorrectAnswers"] + 1;
}
}
This code dosn't contain code responsible for feaching data. It is inside
BussinessLayer.GetExamData() probably.
You can achive random order for example by using
ORDER BY NEWID()
at the end of the query.
You can either use
ORDER BY NEWID();
as Sleipneir proposed, or load the whole whole set of data into a list, and eat that list in a random fashion.
I have a client-server applications I wrote in c#.
My server monitors the commands sent to it by the client.
I wish to send a "finish" message back to the client when the process finishes, I'm just not sure how to do it...
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Management;
using Microsoft.Win32;
namespace RM
{
public partial class RMFORM : Form
{
private Socket clientSock;
private string userName = "";
private string testName = "";
private string testNameString = "";
private string targetPath = "";
private bool isConnected = false;
private TestForm testForm;
private List<string> listOfFilesToCopy = new List<string>();
private List<string> listOfPathToCopy = new List<string>();
private RegistryKey registryKey;
public RMFORM ()
{
InitializeComponent();
userName = RemoteUtils.getConnectedUser();
targetPath = RemoteUtils.targetPath + userName;
testForm = new TestForm(RemoteUtils.remoteIpAddress, userName);
}
private void createNewCommand(string executable, string selectedPath, bool isDirectory)
{
string selectedOutDir = "";
testForm.enableFinishedButton();
testForm.setNumOfProcessesTest();
testForm.ShowDialog();
while (!testForm.getIsFinished())
{
if (testForm.getIsFormClosed())
{
testForm.Hide();
return;
}
}
testName = testForm.getTestName();
testNameString = testForm.getSelectedTestType();
selectedOutDir = targetPath + "\\" + testName;
try
{
if (Directory.Exists(selectedOutDir))
{
DialogResult dialogResult = MessageBox.Show("Test named " + testName + " already exists.\nDo You Wish To Continue?", "Warning!", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No)
{
return;
}
}
else
Directory.CreateDirectory(selectedOutDir);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!");
this.Close();
}
if (testNameString.CompareTo("Mek") == 0)
{
addSingleTest(executable, selectedPath, selectedOutDir, "mek", isDirectory);
}
if (testNameString.CompareTo("Mel") == 0)
{
addSingleTest(executable, selectedPath, selectedOutDir, "mel", isDirectory);
}
if (testNameString.CompareTo("Mem") == 0)
{
addSingleTest(executable, selectedPath, selectedOutDir, "mem", isDirectory);
}
}
private void addSingleTest(string executable, string selectedPath, string outputDir, string testType, bool isDirectory)
{
string commandToRun = "";
commandToRun = targetPath + RemoteUtils.batchRunPath + executable + testForm.getTestPerformance() + " " + selectedPath + " " + outputDir;
if (!isDirectory)
{
commandToRun += "\\" + Path.GetFileNameWithoutExtension(selectedPath) + "." + testType + ".pos " + testType;
}
else
{
commandToRun += " " + testType + " " + testForm.getNumOfProcess();
}
removeOne.Enabled = true;
removeAll.Enabled = true;
sendBtn.Enabled = true;
listORequestedCommands.Items.Add(commandToRun);
listORequestedCommands.Refresh();
}
private bool searchForFiles(string parentDirectory)
{
bool found = false;
if (Directory.GetFiles(parentDirectory, "*" + RemoteUtils.sequenceExtenssion).Length > 0)
return true;
try
{
foreach (string subDir in Directory.GetDirectories(parentDirectory))
{
if (Directory.GetFiles(subDir, "*" + RemoteUtils.sequenceExtenssion).Length > 0)
return true;
found = searchForFiles(subDir);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
this.Close();
}
return found;
}
private void connectBtn_Click(object sender, EventArgs e)
{
try
{
if (!isConnected)
{
registryKey = Registry.CurrentUser.CreateSubKey(RemoteUtils.registrySubKey);
clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
connectBtn.Text = "Disconnect From Server";
connectBtn.Refresh();
clientSock.Connect(RemoteUtils.remoteIpAddress, RemoteUtils.remotePort);
statusColor.BackColor = Color.Green;
statusColor.Refresh();
isConnected = true;
buttonAddDirectory.Enabled = true;
buttonAddFile.Enabled = true;
var backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += (sender1, e1) => RemoteUtils.copyDllsToServer(targetPath);
backgroundWorker.RunWorkerAsync();
}
else
{
registryKey.Close();
connectBtn.Text = "Connect To Server";
isConnected = false;
statusColor.BackColor = Color.Red;
buttonAddDirectory.Enabled = false;
buttonAddFile.Enabled = false;
clientSock.Close();
clientSock.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
this.Close();
}
}
private void sendBtn_Click(object sender, EventArgs e)
{
try
{
string [] commandsInRegistry = registryKey.GetValueNames();
for (int i = 0; i < commandsInRegistry.Length; i++)
{
registryKey.DeleteValue(commandsInRegistry[i]);
}
for (int i = 0; i < listORequestedCommands.Items.Count; i++)
{
clientSock.Send(Encoding.Default.GetBytes(listORequestedCommands.Items[i].ToString() + " <eom> "));
registryKey.SetValue("Command " + (i + 1).ToString(), listORequestedCommands.Items[i].ToString());
}
removeAll_Click(sender, e);
sendBtn.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!");
this.Close();
}
}
private void buttonAddDirectory_Click(object sender, EventArgs e)
{
folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.SelectedPath = "C:\\";
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
string selectedPath = folderBrowserDialog.SelectedPath;
if (!searchForFiles(selectedPath))
{
MessageBox.Show("The directory: " + selectedPath + " doesn't contain sequences.", "Error!");
return;
}
testForm.enableNumOfProcesses();
createNewCommand(RemoteUtils.runBatchScript, selectedPath, true);
}
}
private void buttonAddFile_Click(object sender, EventArgs e)
{
openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = "C:\\";
openFileDialog.Filter = "PMD files (*" + RemoteUtils.sequenceExtenssion + ")|*" + RemoteUtils.sequenceExtenssion + "|All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string selectedFile = openFileDialog.FileName;
if (Path.GetExtension(selectedFile).CompareTo(RemoteUtils.sequenceExtenssion) != 0)
{
MessageBox.Show("The file: " + selectedFile + " is not a sequence file.", "Error!");
return;
}
createNewCommand(RemoteUtils.batchRunExe, selectedFile, false);
}
}
private void removeOne_Click(object sender, EventArgs e)
{
int iRemoveIndex = listORequestedCommands.SelectedIndex;
if (iRemoveIndex > -1)
{
listORequestedCommands.Items.RemoveAt(iRemoveIndex);
listORequestedCommands.Refresh();
if (listORequestedCommands.Items.Count == 0)
{
removeOne.Enabled = false;
removeAll.Enabled = false;
sendBtn.Enabled = false;
}
}
}
private void removeAll_Click(object sender, EventArgs e)
{
listORequestedCommands.Items.Clear();
listORequestedCommands.Refresh();
buttonAddDirectory.Enabled = true;
buttonAddFile.Enabled = true;
removeOne.Enabled = false;
removeAll.Enabled = false;
sendBtn.Enabled = false;
}
}
}
Any ideas?
Have you looked at
http://www.thecodeproject.com/csharp/ZaSocks5Proxy.asp
We use code based on this in our s/w so that our "server" monitors input to broadcasts the message to all other users hooked into the "server"
In essence each workstation monitors in incoming string. The first word of the string we use as a "command" and process accordingly. "finish" could be such a command.