|
First of all, there is no implicit loop operation that breaks out at a specified time interval. You'll have to code it yourself.
Secondly, as your loop depends on reaching a value or a timeout being reached, a for loop is not the appropriate choice - it is designed to work with a fixed number of iterations. In this case, I would choose to use a while loop instead. Then you could do something like the following:
Stopwatch watch = new Stopwatch();
int count = 0;
do
{
if (!watch.IsRunning)
{
watch.Start();
}
PerformSomeLongRunningOperation();
} while (++count < 10 && watch.Elapsed <= TimeSpan.FromSeconds(2) );
watch.Stop();
|
|
|
|
|
Dear all,
In my application i have an XML like this..
I want to perform a search in this XML Based on SubID, ModuleId, TaskName, between start and end dates. Please help me. Also i need all the parents of the searched nodes without siblings.
<Tasks>
<Task TaskId=1 PId=0 SubId=0 ModuleId=0 TaskName="Task 1" StartDate="1 Apr 2011" EndDate="12 Apr 2011">
<Task TaskId=2 PId=1 SubId=0 ModuleId=0 TaskName="Task 2" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId=3 PId=1 SubId=0 ModuleId=0 TaskName="Task 3" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId=4 PId=1 SubId=0 ModuleId=0 TaskName="Task 4" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId=5 PId=1 SubId=1 ModuleId=0 TaskName="Task 5" StartDate="1 Apr 2011" EndDate="12 Apr 2011">
<Task TaskId=6 PId=5 SubId=0 ModuleId=0 TaskName="Task 6" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId=7 PId=5 SubId=0 ModuleId=0 TaskName="Task 7" StartDate="1 Apr 2011" EndDate="12 Apr 2011">
<Task TaskId=8 PId=7 SubId=0 ModuleId=0 TaskName="Task 8" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
</Task>
<Task TaskId=9 PId=5 SubId=0 ModuleId=0 TaskName="Task 9" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
</Task>
<Task TaskId=10 PId=1 SubId=0 ModuleId=0 TaskName="Task 10" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
</Task>
</Tasks>
Please help
Regards,
DJ
|
|
|
|
|
As they are attributes, you need to use attribute based searches in your XPath. The type of syntax you are looking to use is //[@...=value] .
You are going to have a problem with the date part as this stands because your data is all text as far as the parser is concerned. In order to work with date information, you are going to have to provide a schema and set the data types as appropriate.
BTW, your XML is malformed - you must enclose your values in quotes, so having TaskId=9 is incorrect and it should actually be TaskId="9"
|
|
|
|
|
 Re: XML Search
Ok.. fine..
Updated the XML taskXML =
<Tasks>
<Task TaskId="1" PId="0" SubId="0" ModuleId="0" TaskName="Task 1" StartDate="1 Apr 2011" EndDate="12 Apr 2011">
<Task TaskId="2" PId="1" SubId="0" ModuleId="0" TaskName="Task 2" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId="3" PId="1" SubId="0" ModuleId="0" TaskName="Task 3" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId="4" PId="1" SubId="0" ModuleId="0" TaskName="Task 4" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId="5" PId="1" SubId="1" ModuleId="0" TaskName="Task 5" StartDate="1 Apr 2011" EndDate="12 Apr 2011">
<Task TaskId="6" PId="5" SubId="0" ModuleId="0" TaskName="Task 6" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId="7" PId="5" SubId="0" ModuleId="0" TaskName="Task 7" StartDate="1 Apr 2011" EndDate="12 Apr 2011">
<Task TaskId="8" PId="7" SubId="0" ModuleId="0" TaskName="Task 8" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
</Task>
<Task TaskId="9" PId="5" SubId="0" ModuleId="0" TaskName="Task 9" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
</Task>
<Task TaskId="10" PId="1" SubId="0" ModuleId="0" TaskName="Task 10" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
</Task>
</Tasks>
And perform the search criteria as follows (My code)
public XMLNode searchXML()
{
if ((null != taskXML) && 0 < subProjectId)
{
taskXML = taskXML.SelectSingleNode("//Task[@SubId ='" + subProjectId.ToString() + "']");
}
if ((null != taskXML) && 0 < moduleId)
{
taskXML = taskXML .SelectSingleNode("//Task[@TaskId ='" + moduleId.ToString() + "']");
}
if ((null != taskXML) && (null != startDate && null != endDate))
{
taskXML= taskXML.SelectSingleNode("//Task[@StartDate >'" + startDate.ToString() + "']");
if (null != taskXML)
taskXML= taskXML.SelectSingleNode("//Task[@StartDate < '" + endDate.ToString() + "']");
}
if ((null != taskXML) && 0 < statusId)
{
taskXML = taskXML .SelectSingleNode("//Task[@StatusId='" + statusId + "']");
}
if ((null != projectTaskXML) && string.Empty != taskName)
{
taskXML = taskXML .SelectSingleNode("//Task[@TaskName='" + taskName + "']");
}
return taskXML;
}
But the date search and name search not working.
Also i need to get the parents of searched tasks
Could u please help me?
|
|
|
|
|
I already told you that your date search wouldn't work because the data type is a string, and you need to create a schema for this. If you had read my answer fully, you'd have seen that vital piece of information.
|
|
|
|
|
The date search might work if you use the ISO 8601-compliant format YYYY-DD-MM -- which is what the W3C recommends for XML anyway.
|
|
|
|
|
I have a requirement to convert tiff files to pdf. But the problem is, for some tiff files, the header information is missing.
If I opened this tiff files using IrfanView and save it again(I mean overwrite the file in the same location), the header information is automatically added.
Is there any way which I can open those tiff files and save it again (as I done manually using Irfanview) programmatically using C#?
Please provide any solution.
Thanks
meeram395.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
There's a fairly detailed explanation here[^] on writing out a TIFF file.
|
|
|
|
|
We have a good article on CP about this[^]
// ♫ 99 little bugs in the code,
// 99 bugs in the code
// We fix a bug, compile it again
// 101 little bugs in the code ♫
|
|
|
|
|
|
Hello,
I wonder if there is a services-like platform in C# where I can build addons onto. And when I say services, I mean the kind of services Windows has, which I can inject dependencies, trigger a start\stop and add\remove addons as I wish.
I will also need a way of controling it, like a console, MMC or some other kind of UI.
Does anyone know of something similar to what I'm looking for? it'll really help me out
Thanks in advance.
|
|
|
|
|
Just for clarification:
Why not just create windows services that you can control using all the tools you mentioned? What is the requirement that is driving you away from that much simpler solution?
~Justin_H
|
|
|
|
|
I'd like to be able to make it cross-platform using MONO
|
|
|
|
|
I would search codeproject for examples of using Managed Extensibility Framework (MEF). I did a quick search and the latest versions should work under Mono.
Try: http://www.codeproject.com/Articles/56635/Managed-Extensibility-Framework.aspx for a MEF intro.
Going the MEF / roll your own solution route you can't avoid writing some OS specific code to start your "services" with the system but that shouldn't be too hard.
Option 2: Check out http://linux.die.net/man/1/mono-service[^] which basically allows you to run .net windows services under mono/linux with little if any code change required.
~Justin_H
|
|
|
|
|
hi
i want windows application that Frequency-shifting Auditory Feedback from microphone. for example file download from http://www.artefactsoft.com/daf.htm
thanks.
|
|
|
|
|
Is this a C# question?
The best things in life are not things.
|
|
|
|
|
hi
I want a billion dollars and a polygamous relationship with Jennifer Love Hewitt and Angelina Jolie.
thanks.
|
|
|
|
|
ill settle for a million and the rest of that statement
Programming is a race between programmers trying to build bigger and better idiot proof programs, and the universe trying to build bigger and better idiots, so far... the universe is winning.
|
|
|
|
|
Wrong forum, wrong question
|
|
|
|
|
Hi,
I'm working on an end user card editor desktop aplication. The user can drag and drop controls (text, line, shape) from a toolbox to a design area.To create this controls I created my own controls that inherit from my BaseControl class that inherits from Control class. This controls can have a transparent background, and after googleing during days It works with this code.
[Designer(typeof(BaseControlDesigner))]
public abstract class BaseControl:Control
{
public BaseControl()
{
this.DoubleBuffered = false;
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
this.BackColor = Color.Transparent;
}}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle bounds = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
Color frmColor = this.Parent.BackColor;
Brush bckColor;
int alpha = 255;
alpha = (this.Opacity * 255) / 100;
if (this.drag)
{
Color dragBckColor;
if (BackColor != Color.Transparent)
{
int Rb = BackColor.R * alpha / 255 + frmColor.R * (255 - alpha) / 255;
int Gb = BackColor.G * alpha / 255 + frmColor.G * (255 - alpha) / 255;
int Bb = BackColor.B * alpha / 255 + frmColor.B * (255 - alpha) / 255;
dragBckColor = Color.FromArgb(Rb, Gb, Bb);
}
else dragBckColor = frmColor;
alpha = 255;
bckColor = new SolidBrush(Color.FromArgb(alpha, dragBckColor));
}
else
{
bckColor = new SolidBrush(Color.FromArgb(alpha, this.BackColor));
}
if (this.BackColor != Color.Transparent | drag)
{
g.FillRectangle(bckColor, bounds);
}
bckColor.Dispose();
}
}
}
internal class BaseControlDesigner : ControlDesigner
{
private BaseControl myControl;
protected override void OnMouseDragMove(int x, int y)
{
myControl = (BaseControl)(this.Control);
myControl.drag = true;
base.OnMouseDragMove(x, y);
}
protected override void OnMouseLeave()
{
myControl = (BaseControl)(this.Control);
myControl.drag = false;
base.OnMouseLeave();
}
}
That part works, controls can have a transparent background but there is another problem, I think with de z index.If I drag three controls, the last one is not on the top, it's the second one that is in the top and the Bring to Front, Send to Back commands does not work properly as well. It works with only two controls, but it doesn´t if I use more than two.
What can I do to get it work?
Thank you for your help.
Be happy!
|
|
|
|
|
A bad post perhaps, but this question deserves the attention.
Have you tried Refresh()-ing th control to force it to redraw it's children?
|
|
|
|
|
Hi.
Im building a web chat application and im using async sockets in the server-side.
The client connects to the server socket via flash component.
My question is , when does the connection dies? if i close my browser i see that the server is closing the connection. is that because TCP socket sends data every x seconds to check the connection? and if it does , can i rely on it? or should i use UDP socket and try to handle the connection state myself.
Thank you.
|
|
|
|
|
TCP uses an explicit RST (reset) message to close a connection. The connection can also die due to a timeout.
|
|
|
|
|
Where is the timeout for the connection set?
|
|
|
|
|
socket.ReceiveTimeout and SendTimeout
|
|
|
|
|
TCP sockets are by definition reliable. UDP sockets on the other hand are not. As stated above, the browser is closing the connection explicitly.
|
|
|
|