|
OK - I've cracked the issue, but I'm not even going to pretend I know why...it appears it was down to how I was populating my lists....
The pop code originally looked like;
var expandedEntities = Foontities.Select(entity => new ExpandedFoo
{
FooId = entity.fooId.ToString(CultureInfo.InvariantCulture),
BarId = entity.BarId.ToString(CultureInfo.InvariantCulture),
Title = entity.Title,
Gender = entity.Gender,
FirstName = entity.FirstName,
LastName = entity.LastName,
FullName = entity.FullName,
OtherNames = entity.OtherNames,
CombinedName = entity.CombinedName,
Country = entity.Country,
BlahId= entity.BlahId.ToString(),
DateOfBirths = (from DateOfBirth dob in dateOfBirths
where dob.FooId== entity.FooId
select new FooDateOfBirth()
{
DateOfBirthId = dob.DateOfBirthId,
Year = dob.Year,
Month = dob.Month,
Day = dob.Day
}).ToList()
});
Which was causing the 12s time to extract 1000 records, but (as mentioned, this is to index into Elastic Search), converting to Json and building a bulk command using PlainElasic.net was <.2s....
Removing the ToList(), to make the DOB population code;
DateOfBirths = (from DateOfBirth dob in dateOfBirths
where dob.PooId == entity.FooId
select new FooDateOfBirth()
{
DateOfBirthId = dob.DateOfBirthId,
Year = dob.Year,
Month = dob.Month,
Day = dob.Day
})
Fixed the extraction problem and took the time to milliseconds - BUT caused the Json conversion and bulk command building to take (coincidentally) 12s...
HOWEVER, doing;
DateOfBirths = (from DateOfBirth dob in dateOfBirths
where dob.FooId == entity.FooId
select new FooDateOfBirth()
{
DateOfBirthId = dob.DateOfBirthId,
Year = dob.Year,
Month = dob.Month,
Day = dob.Day
}) as List<DateOfBirth>
Made it run in the region of .001s for both the extract and the convert and bulk command creation....
I think I need to look at the IL and see what's going on!
Many thanks to both you and Richard for all your help - if I can figure out the issue / differences, I'll post back and let you both know!
Thanks again gents!
C# has already designed away most of the tedium of C++.
|
|
|
|
|
Just as a test, go back to your ExoandedFoo and change the IEnumerable<DataOrBirth> into a List<DataOfBirth> and populate it using the ToList() method.
This space for rent
|
|
|
|
|
Hi Pete,
Actually I was all sorts of wrong - on deeper investigation, the as statement was failing silently (as it of course should) - a cast rather than the as did indeed throw exceptions left right and centre.
Not a problem, I've taken a different tack now...I may at a later date circle back around and look at it in more detail, but for now it'll do as it is.
Many MANY thanks for your time on this one
C# has already designed away most of the tedium of C++.
|
|
|
|
|
Hi Richard,
I've just posted an update above - very odd, but thought you might like to take a look - it was (apparently) down to how I was populating my data...
Many thanks for all your help and suggestions!
C# has already designed away most of the tedium of C++.
|
|
|
|
|
Dear All,
I am making a C# window program with a function playing a local video using window medial Player. I need a function like capture a image frame from the playing video using a button click that will transfer capture directly into a picturebox, and then save into local desk with a button(save button).
Thank you for your help in advance,
|
|
|
|
|
And what code do you have so far? What, exactly, are you expecting us to provide? I can make an awful lot of assumptions here but assumptions are a bad thing.
This space for rent
|
|
|
|
|
Pete O'Hanlon wrote: I can make an awful lot of assumptions here And the first one is probably correct.
|
|
|
|
|
|
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.
|
|
|
|