|
I would say hours at the most
|
|
|
|
|
Look into variable SCOPE, assuming you are not talking about saving the value past the end of the current session (stopping the application) a variable is available until it runs out of SCOPE. Do NOT fall into the VB trap of making all your variables global or static. Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi!
I have a problem. I have created a time sheet system that enables a person to enter a start time and an end time. It then calculates the total hours worked.
The problem I have is this:
When a person has been on lunch from say 11:00 to 11:30 and then wants to enter a time worked say 11:15 then an exception should be thrown stating that times cannot overlap. How will I go about checking for this?
Thanks in advance!!Illegal Operation
|
|
|
|
|
two intervals [b1,e1] and [b2,e2] overlap when any of the following is true:
b1<=b2<=e1
b1<=e2<=e1
b2<=b1<=e2
b2<=e1<=e2
So start comparing begin and end DateTimes.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
modified on Sunday, February 28, 2010 8:15 PM
|
|
|
|
|
If you google for c# DateRange you will find a number of classes that people have written to address this sort of problem, i.e. dealing with fixed periods of time and testing for intersection with other periods, and so on. One example is here:
http://noticeablydifferent.com/CodeSamples/DateRange.aspx[^]
This example is OK, except I would make it immutable since in its present form it's not thread-safe.
|
|
|
|
|
Hi,
I'm trying to move a file from 1 directory to another.
But no matter what I try, I keep getting this error at runtime:
Cannot create a file when that file already exists.
string[] filePaths = Directory.GetFiles(dir1, "*.txt");
Directory.Move(filePaths[i], checkedFiles);
All the files in filePaths are in bin\debug\FilesToCheck folder
And checkedFiles folder is in bin\debug\checkedFiles
What am I doing wrong?
|
|
|
|
|
Make sure checkedFiles ends on a backslash, making it a folder, not a file.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
It has an ending backslash. The file is made with Path.Combine()
And in there i added the ending slash.
|
|
|
|
|
Please show us the first and last of the filePaths[] elements, and the checkedFiles value, as seen by your app.
Why do you use Directory.Move rather than File.Move ?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
I tried them both. And both give me the same error at runtime.
Here are the 2 elements in the filePaths[]:
[0]"C:\\Users\\The User\\Documents\\Visual Studio 2008\\Projects\\ProjectMultiThread\\ProjectMultiThread\\bin\\Debug\\filesToCheck\\634029044974663752.txt"
[505]"C:\\Users\\The User\\Documents\\Visual Studio 2008\\Projects\\ProjectMultiThread\\ProjectMultiThread\\bin\\Debug\\filesToCheck\\634029930615165770.txt"
The checkedFiles variable:
C:\Users\The User\Documents\Visual Studio 2008\Projects\ProjectMultiThread\ProjectMultiThread\bin\Debug\Checked Files\
I tried the 'checked files' with and without a space.
Just for the record, I'm trying to move this file from folder filesToCheck: '634029930615165770.txt'
To the 'Checked Files' folder.
I have used File.Move and:
FileInfo fi = new FileInfo(this.filesToCheck);modified on Monday, March 1, 2010 5:28 AM
|
|
|
|
|
Luc Pattyn,
I fixed the problem. I found this site:
http://www.devnewsgroups.net/dotnetframework/t1557-file-move-file-copy-exception.aspx[^]
And: Jacky Kwok's reply to someone else's post did the trick.
But I don't quite understood what he said. A quote from what I mean:
[quote]
The "BackUpPath" in both "Copy" and "Move" in your code are directory only.
However, the "File.Copy" and "File.Move" require it is filename.
[/quote]
If I understand this correctly, File.Move wants in both arguments a File name like this:
File.Move(file1, file2);
Isn't that odd? I'm trying to move a file from one directory to another. But here, you're moving a file to another file?
|
|
|
|
|
Yes, File.Move takes two filenames, that is perfectly clear in the documentation.
FYI: when both files reside in the same disk partition, the file data is not copied, the file is just renamed, i.e. one or two folder lists get modified.
The documentation on Directory.Move is not very clear however; AFAIK it can move an entire folder (when given two folder names), or it moves a single file (when given two file names).
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
So you're saying i have to pass the same file name to the destination argument too?
|
|
|
|
|
Hi Luc,
It seems that the files which are moved, are somehow messed up.
- If i try to open it, it's empty and ms windows is 'asking' me if i want to create a new file.
- If i try to delete the file, windows is 'telling' me that the file "is no longer located in the-file-path".
I was hoping you could help me out here.
|
|
|
|
|
hello everybody,
i need to wrap a Queue so multiple threads will be able to add/get messages from it. if the queue is empty - the thread will wait until it has data.
it works for a couple of seconds and then throws an exceptions that my Queue is empty. why is that?
thanks,
public class SyncQueue<T>
{
private Queue<T> queue;
private object readerLock;
private object queueLock;
private AutoResetEvent dataAvailable;
public SyncQueue()
{
this.queue = new Queue<T>();
this.readerLock = new object();
this.queueLock = new object();
this.dataAvailable = new AutoResetEvent(false);
}
public void Enqueue(T item)
{
lock (queueLock)
{
queue.Enqueue(item);
}
dataAvailable.Set();
}
public T Dequeue()
{
lock (readerLock)
{
if (queue.Count == 0)
{
dataAvailable.WaitOne();
}
lock (queueLock)
{
return queue.Dequeue();
}
}
}
} modified on Sunday, February 28, 2010 4:40 PM
|
|
|
|
|
I can't reproduce problem. I used 8 threads and try it also as static.
|
|
|
|
|
 input is: 1,2,3,4,5,6,7,8,9,10 (several times)
namespace Test
{
public class SyncQueue<T>
{
private Queue<T> queue;
private object readerLock;
private object queueLock;
private AutoResetEvent dataAvailable;
public SyncQueue()
{
this.queue = new Queue<T>();
this.readerLock = new object();
this.queueLock = new object();
this.dataAvailable = new AutoResetEvent(false);
}
public void Enqueue(T item)
{
lock (queueLock)
{
queue.Enqueue(item);
Console.WriteLine("Enqueued Item: " + item);
}
dataAvailable.Set();
}
public T Dequeue()
{
lock (readerLock)
{
if (queue.Count == 0)
{
dataAvailable.WaitOne();
}
lock (queueLock)
{
return queue.Dequeue();
}
}
}
}
public class Tester
{
SyncQueue<int> myQ = null;
public Tester(SyncQueue<int> queue)
{
myQ = queue;
}
public void ProcessMessages(object obj)
{
while (true)
{
Console.WriteLine(myQ.Dequeue());
}
}
}
public class Program
{
static void Main(string[] args)
{
SyncQueue<int> myQ = new SyncQueue<int>();
Tester t1 = new Tester(myQ);
Tester t2 = new Tester(myQ);
Tester t3 = new Tester(myQ);
ThreadPool.QueueUserWorkItem(new WaitCallback(t1.ProcessMessages));
ThreadPool.QueueUserWorkItem(new WaitCallback(t2.ProcessMessages));
ThreadPool.QueueUserWorkItem(new WaitCallback(t3.ProcessMessages));
while (true)
{
string[] snumbs = Console.ReadLine().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string snumb in snumbs)
{
myQ.Enqueue(int.Parse(snumb));
}
}
}
}
}
the exception is: Invalid Operation Exception - queue is empty.
any idea?
thanks,
|
|
|
|
|
It was pretty easy to debug when you posted actual test code. The problem lies within AutoResetEvent. WaitOne will not wait till its state isn't resetet. add this:
dataAvailable.Reset()
dataAvailable.WaitOne();
|
|
|
|
|
ok thanks,
but isn't autoResetEvent supposed to change it's own state automatically after WaitOne()?
i thought that's what it is doing...
maybe i don't understand the difference between auto and manual reset events. can anyone explain?
thanks again.
|
|
|
|
|
|
yeah you're right! something is missed up...
that's what made me be confused about my code at first place...
weird.... thank anyway though!
|
|
|
|
|
please help me I want to print saerch results,if I can send them to microsoft report it's better and if I could print it or save it in pdf format it would be good for my work.if one of them is possible please tell me!
|
|
|
|
|
both of them are possible.
For pdf ITextSharp
For ms reports(Crystal I assume) I can't help you => never used them.
But Ging(Google+Bing == Ging) could help 
|
|
|
|
|
thank you for your answer I will test it and tell you about it . but why I have to forget?
|
|
|
|
|
Ive been building an application that reveals information on what image files have been accessed by any given user
RegistryKey OurKey2 = Registry.Users;
OurKey2 = OurKey2.OpenSubKey(userID + "\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\OpenSavePidlMRU\\" + valuename);
foreach (string valuename2 in OurKey2.GetValueNames())
{
DataGridViewRowCollection rows = this.dataGridView3.Rows;
System.Byte[] strByte = (System.Byte[])OurKey2.GetValue(valuename2);
System.Text.Encoding enc = System.Text.Encoding.Unicode;
string myString = enc.GetString(strByte);
rows.Add(myString, valuename);
}
This gives me "䐟ᩇ夃㽲䒧얉镕毾" etc all gibberish
The actual value viewed in the registry doesnt exactly make sense but you can still read it
Can anyone tell me how to either just read a sensible value from it or how to find out what encrypt/encoding the registry uses on these values?
It also seems to only be reading the first part of the value
Thanks in advance Carl
|
|
|
|