|
|
So I'm still playing around with Rx, and usually, I found it very neat:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var Moves = Observable.FromEventPattern<MouseEventArgs>(this, "MouseMove").Select(evt=>evt.EventArgs.GetPosition(this));
Moves.Subscribe(evt => {
this.Title = evt.ToString();
});
}
I do however find it more useful in most cases to send the value using the Select statement. But when I pass this around, I can't unsubscribe to it like so:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var Moves = Observable.FromEventPattern<MouseEventArgs>(this, "MouseMove").Select(evt=>evt.EventArgs.GetPosition(this));
Moves.Subscribe(evt => {
this.Title = evt.ToString();
});
Moves.Dispose();
}
How can I dispose of the subscribtion?
|
|
|
|
|
Nevermind I'm stupid
private void Window_Loaded(object sender, RoutedEventArgs e)
{
IObservable<Point> Moves = Observable.FromEventPattern<MouseEventArgs>(this, "MouseMove").Select(evt=>evt.EventArgs.GetPosition(this));
var DisposableSubscribtion = Moves.Subscribe(evt => {
this.Title = evt.ToString();
});
DisposableSubscribtion.Dispose();
}
|
|
|
|
|
public string ConfidenceConnected(string filename)
{
string ConfidenceConnected = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\image\\ConfidenceConnected.exe";
int seedX = 100;
int seedY = 78;
string file = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\image\\" + filename + " output.dcm" + " " + seedX + " " + seedY;
//string Out = " output"+ filename+".dcm";
string cmd = "/c" + ConfidenceConnected + file;
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = cmd;
process.StartInfo.RedirectStandardOutput = true;
string return_string = " ";
try
{
process.Start();
return_string= process.StandardOutput.ReadToEnd();
}
catch (Exception e)
{
return_string = e.Message;
}
return return_string;
}
|
|
|
|
|
And what problem do you have? That's just a code dump.
This space for rent
|
|
|
|
|
Spaces are a problem here.
First off, you need a space between ConfidenceConnected and file , and before ConfidenceConnected :
string cmd = "/c" + ConfidenceConnected + file;
Otherwise your command string becomes:
/cC:\path\image\ConfidenceConnected.exeC:\path\image\filename output.dcm 100 78
Second, if you want paths with spaces, they need to be delimited with double quotes:
/c "C:\path\image\ConfidenceConnected.exe" "C:\path\image\filename output.dcm" 100 78
But please try to use Path.Combine[^] instead of building your paths manually!
It's a good idea to build your parts, then finalize with a String.Format:
string cmd = string.Format("/c \"{0}\" \"{1}\" {2} {3}", ConfidenceConnected, file, seedX, seedY);
It makes it a lot easier to see the overview of what you are trying to achieve.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
The other day I posted about a problem[^] with FileSystemWatcher raising events before the file is completely copied into the watched folder.
Thanks for Gerry Schmitz[^] I think I've come up with a workable solution:
I would appreciate any comments on this idea.
[1] The FileSystemWatcher detects the file. It's a large file that take a while to get fully copied into the folder:
private void OnCreated(object sender, FileSystemEventArgs e)
{
if (HasAnotherFileEventOccuredRecently(e.FullPath))
{
return;
}
QueueFile(e);
}
The HasAnotherFileEventOccuredRecently method is called to see if this is the first time a FileSystemWatcher event has been raised for the file. Multiple events are raised for the file, so if any events for the file have already been called, then ignore them. I didn't include this code for brevity.
[2] Next QueueFile is called:
private void QueueFile(FileSystemEventArgs fileSystemEventArgs)
{
var worker = new BackgroundWorker();
worker.DoWork += Worker_DoWork;
worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
_queue.Add(worker);
worker.RunWorkerAsync(fileSystemEventArgs);
}
The BG Worker snippets...
private void Worker_DoWork(object sender, DoWorkEventArgs e)
{
var args = (FileSystemEventArgs)e.Argument;
if (args != null)
{
while (!IsFileAvailable(args.FullPath))
{
}
}
e.Result = args;
}
and
private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
var args = (FileSystemEventArgs)e.Result;
var worker = _queue.FirstOrDefault(x => x == sender);
if (worker != null)
{
worker.Dispose();
_queue.Remove(worker);
}
this.OnCreated(args);
}
[3] and finally the IsFileAvailable method:
public bool IsFileAvailable(string filename)
{
var results = false;
try
{
using (var inputStream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.None))
{
results = inputStream.Length > 0;
}
}
catch (Exception)
{
results = false;
}
return results;
}
If it's not broken, fix it until it is
modified 22-Feb-16 16:59pm.
|
|
|
|
|
|
Am trying to get a list of all sql sever instance in my network using this code but i get an empty list
var dt = SqlDataSourceEnumerator.Instance.GetDataSources();
to verify i put in CMD this "sqlcmd -L" and "osql -L" and i get the list.
so what am doing wrong, i dont know if OS matter am using Win10. Also someone know how to do this using dlls thar sqlserver have?
thanks.
|
|
|
|
|
The code I use is pretty much identical:
SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
DataTable dt = instance.GetDataSources();
foreach (System.Data.DataRow row in dt.Rows)
{
Console.WriteLine("ServerName = {0}", row["ServerName"]);
}
I just tried it under Win 10, and it works fine for me.
What does the debugger say?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
i use your code now and it's the same result.
DataTable dt = instance.GetDataSources();
dt.Rows.Count = 0
any idea why?
|
|
|
|
|
How's your network? Can you see any instances in the VS Solution Explorer pane or SSMS?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
as i said before i run this command in CMD "sqlcmd -L" and i get the list, in this case for now just found my server. In "SSMS" and "VS server exporer" i see my server too.
|
|
|
|
|
Very odd - sorry I can't help further, but as I say, it works for me here under Win 10.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
ok man, thanks for your help.
|
|
|
|
|
You're not alone:
Two of the bug reports have been closed as "fixed", but there's no comment from Microsoft on how to obtain the fix.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
At least that explains why it worked here - the app I was testing in targets .NET 3.5.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
As I was putting together a reply to a QA question today (which, imho, implied using a Stack as a DataSource): [^].
Thinking about what may actually happen under the hood when you re-bind a DataSource to a content source so that a databound Control refreshes at run-time, like this: (use of 'DisplayMember and 'ValueMember left out here)
// refresh
bindSource = new BindingSource(); // assume 'bindSource is declared
bindSource.DataSource = StringStack; // assume a valid Stack exists
listBox1.DataSource = bindSource; // yeah, a ListBox is alive
reminded me that I have never been able to find any information on whether this is an "expensive" operation ... and I don't have the hip-high waders and anti-snake-bite anti-venin needed to go into that dismal swamp of CLR/IL.
I'd appreciate your thoughts on the possible memory/computation time associated with this type of operation.
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
modified 22-Feb-16 9:04am.
|
|
|
|
|
You've posted the link to edit your answer, rather than the link to your answer[^].
I'm not sure it makes a lot of sense to ask whether an operation is "expensive" without specifying what you're comparing it to. Everything is expensive if you're comparing it to doing nothing.
There's no need to dig into the IL - the source code[^] is available, along with all of the comments. At a quick glance, the DataSource property setter[^] calls the SetDataConnection method[^], which eventually calls the SetItemsCore method[^]. There's quite a lot going on in there, but nothing that looks particularly horrendous.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Link is fixed, thanks, Richard,
While I appreciate the level you are at, where you can look at .NET source and make informed inferences about potential use-cases, I'm not there, and don't even want to go there ... perhaps if I were forty years younger ...
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
|
|
|
|
|
|
The very same way you added the hidediv() function, add an other function to remove read-only...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
When you have a question about an article, the best place to ask your question is in the forum at the end of that article. There's very little chance that the author is going to see your question in a completely unrelated forum.
This space for rent
|
|
|
|
|
private void Image()
{
string cmd = "/c " + " ImageRegionIterator.exe" + " output.dcm";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = cmd;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
richTextBox1.Text = process.StandardOutput.ReadToEnd();
}
|
|
|
|
|
And what is wrong with what you have done?
|
|
|
|