|
Mind you, I'm not trying to argue with you (just in case you are starting to get annoyed lol)...
The API is implemented as a service (in the DI / SL sense of the word service, not as a Windows Service), so the instance of my API ends up being a static singleton instance inside of the DI container. It wouldn't get disposed unless the user manually called Dispose on the container. Calling Dispose() on the container is only a requirement if the container contains objects with unmanaged resources that need to be freed up. That is *very* rare in my world as 99.99999% of our stuff is strictly managed.
I know I'm sounding picky by not wanting to add any additional burden on developers that I don't need to, but you'd have to understand the type of people I work with to understand why... . Like the type of people who milk a literal 5 minute task for 6 months to a year type of people. Like the type of people who rather then fix memory leaks in applications simply write scripts to reboot the machine daily type of people .
|
|
|
|
|
Isn't a thread an unmanaged resource?
|
|
|
|
|
You mean as in System.Threading.Thread and Tasks? Well, personally, I'm conscientious about cleaning up everything I create, but threads and tasks clean themselves up when they exit. I was more referring to stuff that would cause a memory leak or OS instability if you didn't free it up like say COM objects or unmanaged bitmaps, that sort of thing.
But to your original point, my worker thread is specifically a foreground thread because I WANT it to "hang" / keep the process alive until its done.
I guess what you're saying is that technically this would qualify for my earlier requirement of only forcing the guy to call Dispose() on the container if something needs to be cleaned up, right?
Yeah, I guess... except in my head, I'm differentiating between stock services that are part of my API and magically registered automatically vs. any services the developer registers .
Maybe I shouldn't make that differentiation, but in my company, its perfectly acceptable to blame your co-worker for their screw up in using your framework, better then you getting crap for your "buggy framework"
So that's really why I'm being so picky in trying to handle as much as I can in my API. So any bugs I can just throw back at the developer that he didn't use my framework right. That's how my company works unfortunately.
|
|
|
|
|
Task.Run create a new thread on the threadpool, a backgroundworker that runs in its own thread. That will block until it can join with the main-thread(*!), and die as soon as the main-thread dies (after five seconds), and Joins on the mainthread. It is that task that I moved to a foreground thread, not the worker.
*! that means you wait until the proces exits and this task is stopped. B should never become true.
SledgeHammer01 wrote: Background threads only get killed when there are no more foreground threads. There is one in this case: the Worker. Where does it say that in the documentation? AFAIK, the behaviour of the background thread is not guaranteed when the proces (the main thread) is terminated.
http://msdn.microsoft.com/en-us/library/system.threading.thread.isbackground(v=vs.100).aspx[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It says it right in the documentation you linked:
Quote: Background threads are identical to foreground threads, except that background threads do not prevent a process from terminating
In plain English, background threads do NOT block the process from terminating while foreground threads DO.
Quote: Once all foreground threads belonging to a process have terminated, the common language runtime ends the process. Any remaining background threads are stopped and do not complete.
Says right here that as soon as all foreground threads are finished, the process exits. Background threads are terminated on the spot.
I don't know if you read every post in this thread, but there was one where I posted additional proof of it being broken and that the task is staying around as it should:
http://www.codeproject.com/Messages/4940135/Re-Waiting-for-thread-to-exit.aspx[^]
|
|
|
|
|
SledgeHammer01 wrote: I don't know if you read every post in this thread Yup.
SledgeHammer01 wrote: Says right here that as soon as all foreground threads are finished, the process exits. Background threads are terminated on the spot. The proces is considered terminated if all foreground threads are terminated, true; I do not see a specific guarantee that the background-threads keep running if you kill the mainthread.
I can only confirm that the behaviour is not directly what I expected, as the documentation still does not explain why the first codedump behaves as it does
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
I am really puzzled, I have xz compressed files but I have not found a single library that could decode those files for me.
LZMA SDK has officially XZ support, but that is implemented only in the native C code. The C# code covers LZMA compression only.
Also SevenZipSharp and others failed gracefully, most of them based on the mentioned SDK anyhow.
Does anybody know some library that is actually capable of decompressing XZ in .NET?
I'd also prefer something that works on streams instead of files, so I could download some file and extract the text in the XZ file directly in memory.
Kind regards,
Don Rolando
|
|
|
|
|
I couldn't see much out there myself. As I see it, you have some choices
a) use the c++ code, export the functionality you need as a dll, then p/invoke the dll functions from c#
b) (use a to get started) and port the code from c++ to c#
|
|
|
|
|
Hi all, I am attempting to save images from the desktop in a folder on the server using the following web service code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace MultipleImageUploadDemo
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class SaveImageService : System.Web.Services.WebService
{
public SaveImageService()
{
}
[WebMethod]
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
foreach (string key in files)
{
HttpPostedFile file = files[key];
string fileName = file.FileName;
fileName = context.Server.MapPath("~/Upload/" + fileName);
file.SaveAs(fileName);
}
}
context.Response.ContentType = "image/JPEG";
context.Response.Write("File(s) uploaded successfully!");
}
}
}
I got the following error when I try to run the web service:
System.Web.HttpContext cannot be serialized because it does not have a parameterless constructor.
I looked up the error message online and many posts I came across suggest that I create a parameterless constructor in my web service class which is responsible for deserializing the binary data. I tried that as you can see in my code, but I still get the same error message. If you think there is something else I should try please help. Thanks in advance for your help.
|
|
|
|
|
WebMethod attributes creates a method public and visible outside of your class. To enable to any client call that method the framework/compiler will create a proxy for the method (after all not every client what HttpContext is!). As part of that proxy the call and return parameters are serialized into XML or JSON...That's the part where you run into problem. Your input parameter is of type HttpContext, and that type can not be serialized...
It means that you can not create a method that will receive such a parameter!
In anyway it is sound extremely strange to me! Why should you get HttpContext as call parameter?
As it seams you try to upload files via web service call, you should do some search for samples...
One I found is here: http://blogs.msdn.com/b/codefx/archive/2012/02/23/more-about-rest-file-upload-download-service-with-asp-net-web-api-and-windows-phone-background-file-transfer.aspx[^]
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
תפסיק לספר לה' כמה הצרות שלך גדולות, תספר לצרות שלך כמה ה' גדול!
|
|
|
|
|
My requirements are simple. I need something with the following:
* queue like behavior (FIFO)
* thread-safe
* blocking behavior for get item method
* blocking get item method should be cancellable (cancellationtoken, bool, etc)
* blocking behavior should be 0% CPU / non spinning (no sleeps)
* high performance
So, naturally, I went with BlockingCollectionT. This works fine, and meets all my requirements, however, when you use the cancellable Take(CancellationToken) and cancel the operation, you get 3 exceptions:
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.dll
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.dll
A first chance exception of type 'System.OperationCanceledException' occurred in System.dll
The first 2 are caught inside of the framework and the 3rd I catch in my code. This causes people to complain I tried explaining this is "expected behavior", but you know people...
I looked at BlockingCollectionT in ILSpy and it doesn't seem like its going to be possible to bypass the exception throwing. GOD, I hate APIs that throw exceptions for "normal" behavior.
Seems like everything that uses the cancellationtoken throws exceptions on cancellation?
Any other options that don't throw exceptions on a cancellation?
|
|
|
|
|
"Blocking" and "High performance" are not very compatible.
SledgeHammer01 wrote: Any other options that don't throw exceptions on a cancellation? Catching exceptions is not that expensive. It is with the debugger attached, but you can throw and handle quite a lot of exceptions in a single second if there's no debugger attached.
SledgeHammer01 wrote: Seems like everything that uses the cancellationtoken throws exceptions on
cancellation? Implement your own, disallow cancelling; problem solved.
It would be a cool subject for a CodeProject-contest; writing a fast, multithreaded queue.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
SledgeHammer01 wrote: * blocking get item method should be cancellable (cancellationtoken, bool, etc)
Never understood that need. That can only apply if getting the item requires acquiring other resources and in that case, especially given 5, then either make the caller responsible for that or wrap it is a proxy and that does it.
SledgeHammer01 wrote: I hate APIs that throw exceptions for "normal" behavior.
Its a generic class/API which means if there is a failure mode then it must throw exceptions. If that isn't desirable then write your own. Not that hard and I suspect there are a vast number of examples on the internet.
|
|
|
|
|
jschell wrote: Never understood that need. That can only apply if getting the item requires
acquiring other resources and in that case, especially given 5, then either make
the caller responsible for that or wrap it is a proxy and that does it.
I have a worker thread that monitors the queue. There is not always something in the queue. In fact, most of the time, it will be empty or close to it. Clearly, I should not spin the CPU when the queue is empty.
As for being able to cancel the blocking operation, well... if you wait on a syncronization object indefinitely (the blocking part), it keeps the thread alive (which will keep the process alive) [EDIT: unless the thread is a background thread]. Not a desirable behavior when you, say, want to be able to shut down your app .
Using a timeout is also not a solution, as if you set your timeout too low, you'll spin the CPU, and if you set it too high, you'll have that annoying behavior of your app taking a long time to shut down.
jschell wrote: Its a generic class/API which means if there is a failure mode then it must
throw exceptions.
I wouldn't consider cancelling a blocking operation to be a failure if the cancellation was intended. But some would...
jschell wrote: Not that hard
and I suspect there are a vast number of examples on the internet.
You'd be surprised .
|
|
|
|
|
How to calculate matrix determinant? n*n
|
|
|
|
|
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
A very quick search using your subject as the search term gave 71 million hits: Google: "How to calculate matrix determinant? n*n"[^]
In future, please try to do at least basic research yourself, and not waste your time or ours.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Where are you stuck?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have a DVR and configured my router for NAT Forwarding to my web (9000) and media (9100) port. Using a browser and in different network, I cannot access my DVR's web port and see real-time using IE.
I would like to ask where to begin in programming using C# to develop and application for Windows Phone 8.x or Android for my DVR's media port.
Thanks!
|
|
|
|
|
Strange port numbers are often blocked by the ISP. Try another port.
Benjie Fallar III wrote: real-time using IE. You mean "live". Windows isn't a realtime OS.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: Windows isn't a realtime OS.
The deuce you say.
|
|
|
|
|
I have NO problem accessing the media port via LAN/WLAN.
My question is how or where can I start developing a C# programming that capture the live streaming of my DVR cameras from a network.
For example, my DVR media port is 9100 and the IP is 192.168.1.3, thus how can I read the live stream from 192.168.1.3:9100 using C#.
|
|
|
|
|
I have NO problem accessing the media port via LAN/WLAN.
My question is how or where can I start developing a C# programming that capture the live streaming of my DVR cameras from a network.
For example, my DVR media port is 9100 and the IP is 192.168.1.3, thus how can I read the live stream from 192.168.1.3:9100 using C#.
|
|
|
|
|
Benjie Fallar III wrote: I have NO problem accessing the media port via LAN/WLAN.
I cannot access my DVR's web port and see real-time using IE.
Benjie Fallar III wrote: where can I start developing a C# programming that capture the live streaming of
my DVR cameras Do you know the format of the stream? Any other application that accepts the address/port and can display the stream?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
the streaming format is H.264
is there any online documentation or reference on how to start programming live streaming from DVR using C#.NET?
In some Adroid app, like ViewCam, they can connect to remote DVR. I wanted to develop the same application for Windows Phone. So I'm looking for some references to starts with
|
|
|
|