|
Naturally if the application isn't running (regardless of the type of application) it can't monitor file changes.
Excluding design problems which would stop this, the solution is that when the application starts up it looks for new files. That solution has nothing to do with FileSystemWatcher.
|
|
|
|
|
byka wrote: How to I process those files ?
How about making a list of files that are "there" in the directory that you're watching when the service is started, and process those?
I are Troll
|
|
|
|
|
Just enumerate the files in that folder, create the EventArgs, and call the handler, e.g. in C#:
foreach (string filename in Directory.GetFiles(fsw.Path))
{
FileSystemEventArgs e = new FileSystemEventArgs(WatcherChangeTypes.Created, fsw.Path, filename);
File_Created(this, e);
}
|
|
|
|
|
how can i connect visual studio 2008 application to sql server 2008 using ODBC?
|
|
|
|
|
Why would you want to? ODBC is the method of last resort, to be used when nothing else will work, and VS 2008 comes with classes optimized for connecting to SQL Server. The only excuse for using ODBC is if your application has to interface with other database products after you're done developing it, and you want to minimize the amount of customization required for installation. Use the classes in System.Data.Sql to access a SQL Server database. If you need to rehost the solution to another database, you might duplicate the functionality you build for SQL Server using the namespace, System.Data.Odbc and use the installer to select which method is implemented.
Will Rogers never met me.
|
|
|
|
|
Hey wow, you say that like you know what you're talking about.
Roger Wright wrote: Why would you want to?
Because it's there. I don't know about the OP, but I just like to try things out -- I'll try most anything once. And I like to test my database code in a number of configurations.
My first experience with Sql Server (v6 circa 1999) was with ODBC... brings back memories... ones better left forgotten.
|
|
|
|
|
I've learned a thing or two hanging around this unsavory lot.
As a result, I've given up driving square pegs in round holes, among other bad habits. Just because I can doesn't mean I should.
Will Rogers never met me.
|
|
|
|
|
|
Hi,
MahaKh wrote: how can i connect visual studio 2008 application to sql server 2008 using ODBC?
Here's an example that works for me (.NET 2.0, W7, SQL 2005)
using (OdbcConnection con = new OdbcConnection(
"DRIVER={SQL Server};SERVER=.;Trusted_connection=yes;DATABASE=AdventureWorks;"))
using (OdbcCommand cmd = con.CreateCommand())
{
con.Open();
cmd.CommandText = @"
SELECT FirstName
FROM Person.Contact
WHERE ContactID = 20";
string 结果 = (string)cmd.ExecuteScalar();
MessageBox.Show(String.Format(
"The FirstName of Person.Contact is '{0}'.", 结果));
}
..and this on top of that unit, between the other imports and the namespace-declaration;
using System.Data.Odbc;
And here's the manual[^]
I are Troll
|
|
|
|
|
thanks to all, but my requirement is to use OLEDB instead of ODBC....
|
|
|
|
|
MahaKh wrote: but my requirement is to use OLEDB instead of ODBC
The requirement should state that you should use a SqlConnection . Anyway, the difference between the code is relatively subtle;
using (OleDbConnection con = new OleDbConnection(
"Provider=SQLNCLI;Server=.;Database=AdventureWorks;Trusted_Connection=yes;"))
using (OleDbCommand cmd = con.CreateCommand())
{
con.Open();
cmd.CommandText = @"
SELECT FirstName
FROM Person.Contact
WHERE ContactID = 20";
string result = (string)cmd.ExecuteScalar();
MessageBox.Show(String.Format(
"The FirstName of Person.Contact is '{0}'.",
result
));
} Code tested and verified on W7, .NET 2.0, SQL2k5
I are Troll
|
|
|
|
|
I have noticed looking at MS source that they regularly do this for a class with only static methods instead of creating a static class:
public class ClassName
{
private ClassName()
{ }
public static void Method()
{
}
}
Is there any benifit to this that I'm missing over a static class?
|
|
|
|
|
Perhaps so the class can be inherited? just a guess
Don't vote my posts down just because you don't understand them - if you lack the superior intelligence that I possess then simply walk away
|
|
|
|
|
A class with a single private default constructor cannot be inherited. It will always need some way to instantiate the parent...
|
|
|
|
|
Yes well spotted. Thou I am not assuming the op sample code is 100% correct still
I may or may not be responsible for my own actions
|
|
|
|
|
Pre version 2? Backward compatibility?
|
|
|
|
|
Which sounds plausable, but why allow the class to be instanced (by making it non-static) when it can never be instantiated (because the constructor is private)? Backwards compatibility is going to break anyway, just in a much more awkward spot.
|
|
|
|
|
Private, schmivate; I can call a private constructor or anything else -- which is why they introduced static classes in .net 2.
|
|
|
|
|
COM Interop?
COM requires a public constructor without parameters, and there it is.
And isn't it possible to access class methods through an instance with COM? When I remember those times when I was VB programmer correctly, that was possible, but I am not sure.
|
|
|
|
|
I think this is laziness on the part of MS. If (when?) the class definition changes in the Framework, the documentarians won't have to root around in the code to make sure that every method is still static.
|
|
|
|
|
I don't think your argument is valid. Static methods in non-static classes have their own uses. I have given one such (trivial) example.
Cheers,
Karthik
|
|
|
|
|
I agree: I use static methods in non-static classes all the time. But the question was about non-static classes with nothing BUT static methods.
|
|
|
|
|
Yes, I noticed that later. So I also updated my answer to take that in to account (see EDIT in my answer)...
Cheers,
Karthik
|
|
|
|
|
You could use static methods if the functionality of the method is not dependent on the instance properties/methods. Consider the following class as an example. There is a static "Parse" method that takes in a string and return a new instance of "Data". This static function "does not" depend on any of the instance properties/methods of the Data class. But it just creates an instance of the Data class for you to use. So, any other class that wishes to create an instance of Data (which has a ',' seperated int's) can do so by calling Data.Parse(_stringValue) .
public class Data
{
private List<int> a;
public Data()
{
a = new List<int>();
}
public Data(int[] nums)
{
a = new List<int>();
}
public static Data Parse(string nums)
{
string[] _nums = nums.Split(",".ToCharArray());
List<int> iList = new List<int>();
foreach(string s in nums)
iList.Add(int32.Parse(s));
return new Data(iList.ToArray());
}
}
PS - This is a just a trivial example of the usage of static methods in a non-static class.
Edit - If there are only static methods in a non-static, it might be useless, but it could also be for futuristic reasons. They could add to this class more instance properties / methods in the future that would use these static methods.
Cheers,
Karthik
|
|
|
|
|
Hello,
I am new to wpf. I am creating a application in which I wanted to change my image dynamically with some URL.
I am using code like
TheBinding is property which returns URL.
I tried lot other ways. But nothing is working.
Thanks in advance.
|
|
|
|