|
Hey all,
I'm writing an application where a FileSystemWatcher is monitoring for the addition of new files in a specific directory. When new files are detected the handler for the FileSystemWatcher.Created event captures information about the file and stores it in another object. What I need to do at this stage is start a Timer, when the first file is detected, for 5 seconds. If another file is detected before the Timer expires then the Timer should gain another 5 seconds. This should continue until the FileSystemWatcher hasn't detected a new file for five seconds, at which time the batch of captured data is moved to another stage of processing.
I think a Timer would be the best way to handle this need but I'm not sure. Do you guys think I'm on the right track or can you think of a better way to handle this kind of batched capture-and-release? I've been working on it for couple of days now and am totally confused. Any advice would be greatly appreciated.
Thanks.
-- DDennison
|
|
|
|
|
I am wanting to add a blank line to a datagrid so the user can enter new info. I found an example online (Newbie here!) that shows how to do it, but it only uses one table:
protected void dg_bind() {<br />
<br />
System.Data.SqlClient.SqlConnection SqlCon = new System.Data.SqlClient.SqlConnection( "server=localhost;database=northwind;trusted_connection=true;" );<br />
System.Data.SqlClient.SqlDataAdapter SqlDa = new System.Data.SqlClient.SqlDataAdapter( "SELECT TOP 10 ProductName FROM Products", SqlCon );<br />
ds = new System.Data.DataSet( );<br />
SqlDa.Fill( ds, "Products" );<br />
System.Data.DataRow BlankRow = ds.Tables[ "Products" ].NewRow( );<br />
BlankRow[ "ProductName" ] = "<font color=\"red\">add new product</font>";<br />
ds.Tables[ "Products" ].Rows.InsertAt( BlankRow, 0 );<br />
dg.DataSource = ds.Tables[ "Products" ];<br />
}
Currently my own BindData function looks like this:
private void BindData()<br />
{<br />
strPartNumberInputReference = txtPartNumberInput.Text;<br />
string SQLString = "SELECT c.cost, pt.description, dd.DrawingNumber, dd.DrawingRevision, dd.DwgPath FROM costs c INNER JOIN Parts p ON c.PartID = p.Id INNER JOIN PartTypes pt on pt.ID = p.PartTypeID LEFT JOIN DraftingData dd on dd.PartID = p.ID WHERE p.PartNumber = @PartID";<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = new SqlConnection(strConnectSQL);<br />
cmd.CommandText = SQLString;<br />
cmd.Parameters.Add ("@PartID", strPartNumberInputReference);<br />
SqlDataAdapter adapter = new SqlDataAdapter(cmd);<br />
DataSet ds = new DataSet();<br />
adapter.Fill(ds);<br />
dgParts.DataSource = ds;<br />
dgParts.DataBind();<br />
}
How do I convert that first code that I bolded to work with my program and multiple tables?
|
|
|
|
|
Hi i have a tab control with several tab. I want to each time when i enter a tab the font become bold. i couldn't find a property for that. I know i can handle it at the enter event but don't know how.
Any suggestion?
Donkaiser
|
|
|
|
|
I did something like that once. It went a little somethin' like this...
private Font boldFont;
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
if( this.boldFont == null )
this.boldFont = new Font( this.tabControl1.Font, FontStyle.Bold );
TabPage page = this.tabControl1.TabPages[e.Index];
bool selected = page == this.tabControl1.SelectedTab;
StringFormat frmt = new StringFormat();
frmt.LineAlignment = StringAlignment.Center;
using( Brush brush = new SolidBrush( page.BackColor ) )
e.Graphics.FillRectangle( brush, e.Bounds );
e.Graphics.DrawString( page.Text, selected ? this.boldFont : this.tabControl1.Font, SystemBrushes.ControlText, e.Bounds, frmt );
}
HAPPY WEEKEND!!!
Josh
|
|
|
|
|
I pasted ur code and the event is not firing up. i even got to property and doubleclick on drawItem.
Donkaiser
|
|
|
|
|
Oops, forgot to mention that you need to set the TabControl's DrawMode to the non-default value (OwnerFixed?).
Josh
|
|
|
|
|
Thanks a lot for your help. It's ridiculous that to change the font of the title is so complicated.
your code is working but when a tabpage is not selected the font is not appearing fully on the tab title. I'm planning to resize the page title, is there a way to do that?
Donkaiser
|
|
|
|
|
the option appears on the tabcontrol in item size. don't forget to set size mode to fixed.
Donkaiser
|
|
|
|
|
Hi
am new to windows service.what ever samples i see ,it is described that by default the servicebase class will be available, after that the installer needs to be added .
It makes sense that the installers are needed to install the service to the OS as a service . But i don't find any code relations that the service class refers the installer classes .
Please xplain me
1. where is the link between the service class & the installer
2. how the installer identifies which service needs to be installed(service seems accepts any text string not hardly the service class)
Thanks & Regards
Raghuraman.C
|
|
|
|
|
Hello,
Can anyone tell me how I can locate a program that is minimized to the system tray. I know the Process Id of the application, but when I call Interaction.AppActivate using the process Id I get an ArgumentException exception. However, I don't know the title of the application to use the (Win32)FindWindow method.
Apparently programs that run in the system Tray can not be retrieved using this method. I am able to retrieve all other types of programs using this method.
Here is my code that locates the application and activates it to bring it to the front.
private void onLocateApplicationButtonClick(object sender, EventArgs e)<br />
{<br />
if ((null != sender)<br />
&& (sender is Control)<br />
&& (null != ((Control)sender).Tag)<br />
&& (((Control)sender).Tag is int))<br />
{<br />
int app_index = (int)((Control)sender).Tag;<br />
<br />
try<br />
{<br />
Interaction.AppActivate(m_processes_list[app_index].Id);<br />
}<br />
catch (ArgumentException aex)<br />
{<br />
Console.WriteLine("{0}", aex.Message);<br />
}<br />
}<br />
}
Any one have a suggestion?
Thanks,
DP
|
|
|
|
|
Maybe this will give you a head start, ignore the custom types referenced that aren't included in this code. If you have the process id, you should be able to identify it while looping through all processes. You'll probably need to use the CaptureWindowless() example.
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Runtime.InteropServices;
using BoneSoft.LinksLibrary;
namespace LinksLibrarian2 {
public class ProcessCapturer {
static ProcessCapturer() {}
public static ShortCuts CaptureWindows() {
ShortCuts scs = new ShortCuts();
scs.AddRange(CaptureFolders());
scs.AddRange(CaptureIEs());
Process[] localAll = Process.GetProcesses();
foreach (Process p in localAll) {
try {
if (p.MainWindowTitle.Equals(string.Empty)) { continue; }
ShortCut esc = null;
esc = new ExeShortCut(p.MainWindowTitle, p.MainModule.FileName);
if (esc == null) { continue; }
esc.Description = p.ProcessName;
scs.Add(esc);
} catch {}
}
return scs;
}
public static ShortCuts CaptureWindowless() {
ShortCuts scs = new ShortCuts();
Process[] localAll = Process.GetProcesses();
foreach (Process p in localAll) {
try {
if (!p.MainWindowTitle.Equals(string.Empty)) { continue; }
ShortCut esc = null;
esc = new ExeShortCut(p.ProcessName, p.MainModule.FileName);
if (esc == null) { continue; }
esc.Description = p.ProcessName;
scs.Add(esc);
} catch {}
}
return scs;
}
}
}
Visit BoneSoft.com
|
|
|
|
|
Thanks for your help.
I used your 'CaptureWindowless' example to verify that the Process Id I have is in the list of all Processes and it is. However, I am still unable to Activate that given process so that it brings my application to the front.
Using your code I added the following try-catch once I verify the Process is in the list. And I pass the process name to the (Win32) method, FindWindow, and it returns zero - could not find it.
try
{
Interaction.AppActivate(id);
}
catch (ArgumentException)
{
uint hwndInstance = FindWindow(null, p.ProcessName);
}
|
|
|
|
|
Hey Everyone,
This is my 2nd day using C# and so far it's been pretty cool. I'm trying to write an application that will return system information to me such as the processor type and RAM speed of a system. Any idea how I would go about that?
Thank you in advance.
-Karthik Gaekwad
|
|
|
|
|
|
That is perfect! Thanks a million.
-K
|
|
|
|
|
I have a typed dataset with an integer value called FiscalMonth. What I want to do is bind it to a combobox that is preseeded with a list of integers from 1-12.
Here's what I have so far:
<br />
for (int i = 1; i <= 12; i++)<br />
{<br />
uxcbFMonth.Items.Add(i);<br />
}<br />
<br />
mySource = new BindingSource();<br />
<br />
mySource.DataSource = myManagerClient.VersionTable.Select("VersionKey = " +VersionKey.ToString())[0];
That seems to work just fine, the combobox is populated, and in the text fields, the databinding (using Control.DataBindings.Add) works. The problem is it doesn't appear as if the combobox databinding works, because when I try to change it the control locks and remains selected until I manually close the application.
I assign the databindings like this:
uxcbFMonth.DataBindings.Add("SelectedValue", mySource, "FiscalMonth", true, DataSourceUpdateMode.OnValidation);
Am I binding to the wrong value? Any ideas?
|
|
|
|
|
I have a Word template with 13 docVariables. In C# word interop code stuffers I have to access them with Field[1].Select() and then populate the selection (Variables come up empty).
My problem: Is there a way to rather call Field["varname"] instead of recalling Field[1] over and over again. If not, is there a way to ensure that I have the correct field, instead of hoping I counted correctly?
|
|
|
|
|
You could use an enum. Or a Dictionary. Just thinking about simple solutions.
Logifusion[^]
|
|
|
|
|
Dictionary?
Everything works fine, the guy I'm doing it for just wants to be super sure that the correct fields get filled out... Seeing as its his, ahem, rear on the line, I can understand his concern.
|
|
|
|
|
Well, you can write an enum like this:
public enum MyDocFields {
FirstField = 0,
SecondField = 1,
...
}
Or you can use a Dictionary:
Dictionary<string, int> dictDocFields = new Dictionary<string, int>();
dictDocFields.Add("FirstField", 1);
...
Basically just use anything that eventually gets you back to an integer.
Logifusion[^]
|
|
|
|
|
Doesn't really solve my problem, but thanks a lot anyway...
My main problem is that I need to prove from the document that I am working with the correct field, assigning my own names to the field does not quite cut it...
Oh well, always was one for self inflicted torture
Thanks for your help
|
|
|
|
|
This code below is pretty long. Wonder if its possible to shorten the code?
the sender would be the combo box... I have 7 comboboxes on the window as part for Filtering the data from the raw data and the cbMath<x> comboboxes are independent.
Can anyone make any suggestion?
#region private void cbMath_IndexChanged(object sender, System.EventArgs e)
private void cbMath_IndexChanged(object sender, System.EventArgs e)
{
ComboBox cb = (ComboBox)sender;
switch (cb.Name.ToString())
{
case "cbMathA":
{
if (this.numericUpDownAL.Visible && this.cbMathA.Text == "Range")
{
this.numericUpDownAR.Visible = true;
}
else
{
this.numericUpDownAR.Visible = false;
}
if (this.dateTimePickerAL.Visible && this.cbMathA.Text == "Range")
{
this.dateTimePickerAR.Visible = true;
}
else
{
this.dateTimePickerAR.Visible = false;
}
break;
}
case "cbMathB":
{
if (this.numericUpDownBL.Visible && this.cbMathB.Text == "Range")
{
this.numericUpDownBR.Visible = true;
}
else
{
this.numericUpDownBR.Visible = false;
}
if (this.dateTimePickerBL.Visible && this.cbMathB.Text == "Range")
{
this.dateTimePickerBR.Visible = true;
}
else
{
this.dateTimePickerBR.Visible = false;
}
break;
}
case "cbMathC":
{
if (this.numericUpDownCL.Visible && this.cbMathC.Text == "Range")
{
this.numericUpDownCR.Visible = true;
}
else
{
this.numericUpDownCR.Visible = false;
}
if (this.dateTimePickerCL.Visible && this.cbMathC.Text == "Range")
{
this.dateTimePickerCR.Visible = true;
}
else
{
this.dateTimePickerCR.Visible = false;
}
break;
}
case "cbMathD":
{
if (this.numericUpDownDL.Visible && this.cbMathD.Text == "Range")
{
this.numericUpDownDR.Visible = true;
}
else
{
this.numericUpDownDR.Visible = false;
}
if (this.dateTimePickerDL.Visible && this.cbMathD.Text == "Range")
{
this.dateTimePickerDR.Visible = true;
}
else
{
this.dateTimePickerDR.Visible = false;
}
break;
}
case "cbMathE":
{
if (this.numericUpDownEL.Visible && this.cbMathE.Text == "Range")
{
this.numericUpDownER.Visible = true;
}
else
{
this.numericUpDownER.Visible = false;
}
if (this.dateTimePickerEL.Visible && this.cbMathE.Text == "Range")
{
this.dateTimePickerER.Visible = true;
}
else
{
this.dateTimePickerER.Visible = false;
}
break;
}
case "cbMathF":
{
if (this.numericUpDownFL.Visible && this.cbMathF.Text == "Range")
{
this.numericUpDownFR.Visible = true;
}
else
{
this.numericUpDownFR.Visible = false;
}
if (this.dateTimePickerFL.Visible && this.cbMathF.Text == "Range")
{
this.dateTimePickerFR.Visible = true;
}
else
{
this.dateTimePickerFR.Visible = false;
}
break;
}
case "cbMathG":
{
if (this.numericUpDownGL.Visible && this.cbMathG.Text == "Range")
{
this.numericUpDownGR.Visible = true;
}
else
{
this.numericUpDownGR.Visible = false;
}
if (this.dateTimePickerGL.Visible && this.cbMathG.Text == "Range")
{
this.dateTimePickerGR.Visible = true;
}
else
{
this.dateTimePickerGR.Visible = false;
}
break;
}
default: return;
}
}
|
|
|
|
|
I had to do something similar to this myself. I used reflection. Here's kinda what I would do:
char endChar = cb.Name[cb.Name.Length - 1];
FieldInfo fiNumL = this.GetType().GetField("numericUpDown" + endChar + "L");
FieldInfo fiNumR = this.GetType().GetField("numericUpDown" + endChar + "R");
FieldInfo fiMath = this.GetType().GetField("cbMath" + endChar);
Control cNumL = fiNumL.GetValue(this) as Control;
Control cNumR = fiNumR.GetValue(this) as Control;
Control cMath = fiMath.GetValue(this) as Control;
cNumR.Visible = (cNumL.Visible && cMath.Text == "Range");
It's not complete, but hopefully it makes sense. If you're not comfortable with reflection, just shorten your if statements:
this.numericUpDownGR.Visible = this.numericUpDownGL.Visible && this.cbMathG.Text == "Range";
Logifusion[^]
|
|
|
|
|
Hmmm I like the suggestion. I'll look into these possiblites. Thanks!
|
|
|
|
|
The 2nd suggestion made by LogiFusion makes more sense to me. Its much straightforward. It helped to shrink the switch statement from 151 lines to 46 lines.
Thanks a heap!
|
|
|
|