|
Why not?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Well, does it increase throughput? If not, it's a make-work project.
|
|
|
|
|
It's possible for many files to be dropped into the folder at once, so I want to send more than one at a time to decrease the total time it takes to get them to the server.
If there's a lot of files and they go one at a time it could take forever for them to finish.
I set it to 3 for starters but if it works well I could up it to 5 or even 10. Each one will be in it's own process so they should all go concurrently.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Are you sending to different destinations? If not, have you determined that transmitting more than one at a time reduces the overall elapsed time?
It's hard to optimize a solution when there is no apparent benefit.
|
|
|
|
|
I can't see why FTP'ing more than file at a time wouldn't work. It would certainly be quicker than sending them one at a time.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Everything is going through the same "hose".
In addition, you now have to consider the potential for multiple failed FTP's in progress.
|
|
|
|
|
Not necessarily.
Sending 3 files at the same time is not any faster than sending the same 3 files one at a time. The network pipe can still only send one bit at a time, not 3. The benefit you get from sending multiple files at the same time is limited to the amount of time it takes to send and receive FTP protocol data for each file, not the file data you're sending. This including starting the FTP session, authentication, navigation, file transfer commands, file framing data, acknowledgments, ...
Since, in both test cases, you're sending the exact same file data, the timings of sending the actual file data cancel each other out. It may indeed be faster, but you're not going to see a result of sending 3 files at the same time takes 33% of the time of sending one at a time.
|
|
|
|
|
So are you saying that there's no benefit in sending multiple files at once? If so, what's the right way to do it?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
No, I'm saying that you're not going to get the boost in speed you think you're going to get.
|
|
|
|
|
So it sounds like it's best to just send one file at a time?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
(A cry in the wilderness)
|
|
|
|
|
What?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
It's the easiest to implement.
If you're trying to get someone to make the decision for you, it's not going to happen. It's up to you to evaluate how much work this is going to be for you and whether or not it's going to be worth it.
|
|
|
|
|
I'd be inclined to simplify that.
Start with a general-purpose async throttle, inspired by code from Stephen Toub's blog[^]:
public sealed class Throttle
{
private readonly Queue<TaskCompletionSource<IDisposable>> _waiters = new Queue<TaskCompletionSource<IDisposable>>();
private readonly WaitCallback _releaseCoreCallback;
private readonly Task<IDisposable> _releaserTask;
private readonly Releaser _releaser;
private readonly int _maxCount;
private int _currentCount;
public Throttle(int initialCount)
{
if (initialCount <= 0) throw new ArgumentOutOfRangeException();
_maxCount = _currentCount = initialCount;
_releaser = new Releaser(this);
_releaserTask = Task.FromResult((IDisposable)_releaser);
_releaseCoreCallback = ReleaseCore;
}
public Task<IDisposable> WaitAsync()
{
lock (_waiters)
{
if (_currentCount > 0)
{
_currentCount--;
return _releaserTask;
}
var waiter = new TaskCompletionSource<IDisposable>();
_waiters.Enqueue(waiter);
return waiter.Task;
}
}
private void Release()
{
TaskCompletionSource<IDisposable> toRelease = null;
lock (_waiters)
{
if (_waiters.Count > 0)
{
toRelease = _waiters.Dequeue();
}
else if (_currentCount < _maxCount)
{
_currentCount++;
}
else
{
throw new SemaphoreFullException();
}
}
if (toRelease != null)
{
ThreadPool.QueueUserWorkItem(_releaseCoreCallback, toRelease);
}
}
private void ReleaseCore(object state)
{
((TaskCompletionSource<IDisposable>)state).SetResult(_releaser);
}
private sealed class Releaser : IDisposable
{
private readonly Throttle _throttle;
public Releaser(Throttle throttle)
{
_throttle = throttle;
}
public void Dispose()
{
_throttle.Release();
}
}
}
That gives you a simple way to restrict the number of async methods which can access a resource simultaneously.
Your FTPQueue class then becomes:
public static class FTPQueue
{
private const int MAX_FILE_UPLOADS = 3;
private static readonly Throttle UploadThrottle = new Throttle(MAX_FILE_UPLOADS);
public static async Task FileReceived(string fileName)
{
Console.WriteLine("Received file {0}", fileName);
using (await UploadThrottle.WaitAsync())
{
Console.WriteLine("Uploading file {0}", fileName);
bool result = await TransferFile(fileName);
if (result)
{
Console.WriteLine("Finished uploading {0}", fileName);
}
else
{
Console.WriteLine("Failed to upload {0}", fileName);
}
}
}
private static async Task<bool> TransferFile(string fileName)
{
await Task.Delay(10000);
return true;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Interesting.. I'll take a look.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hi All,
I have built a windows forms application using VS2005.
There is a textbox and button in the form. I have created a shortkey [Ctrl+u] on using the shortcut a file browser will open successfully. After selecting the files the text "u" is being printed in the textbox.
Please guide me to resolve this issue.
Thanks in advance.
Thanks
Prabhanjan
|
|
|
|
|
Without seeing the relevant fragments of your code? We can't do anything to help you: we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Change the code so that the u is not printed in the textbox.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
How did you "wire-up" your short-cut key? WPF? Windows Forms? ...
|
|
|
|
|
In C#, Asked about the code of the button Decrease Indent and button Increase Indent for RichTextBox ? do you know share with me ?
|
|
|
|
|
|
Good morning to all.
So about 8 minutes ago I discovered the existence of something called ConfigR, available through nuget. The idea is you write your config files in c# rather than xml which allows for strong typing, this is the compiled at runtime to a real object.
Or something like that.
I'm going to investigate further, but I have an immediate question - what are the security implications of this and does this open the door to script injection like attacks? Anyone had any experience with this thing?
Regards,
Rob Philpott.
|
|
|
|
|
According to the project site[^]:
Quote: you can write any C# you like in your 'configuration file'
That would seem to suggest that the configuration file can be used to inject code into your process.
But if an attacker can modify your config file, then they already have access to your system, and they can probably do a lot worse.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I can convert image to binary string from
[HERE]
But This binary string how to convert the that image ?
|
|
|
|