|
Well, if it does, the code isn't really parallelizable. If each iteration of the for loop overwrites the variable in a way that is dependent on previous iterations, it doesn't really make sense to parellilize it. For example, if it really is calculation of primes, then numbers = 10000 could run before numbers = 2.
|
|
|
|
|
|
Good question!
The problem you have is that you don't know the bounds of your input - you don't know how big number will have to get to generate the required number of primes .
However, you can still parellelise chunks of work - something like this:
const int N = ( int ) 1e6;
static readonly int STEP = Environment.ProcessorCount * ( int ) 1e6;
...
var primes = new List<int>( N );
for ( int start = 2 ; primes.Count < N ; start += STEP )
primes.AddRange(
Enumerable.Range( start, STEP )
.AsParallel().AsOrdered()
.Where( i => IsPrime( i ) ) );
primes = primes.Take( N ).ToList();
You'll have to tune the values of N and STEP for your specific case.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Hi,
In an application playing number of files from a folder, i need to use slide bar.
How can i implement in my application. I am using 2005 framework.
Thankyou,
YPKI
|
|
|
|
|
What do you want the slidebar to look like, and even more important, what do you want the slide bar to represent?
|
|
|
|
|
Hi,
I am working on a small application that checks what browsers are installed on a system running Windows Xp... I was able to find the right entries to check whether Firefox and Chrome are installed or not... And after quite some amount of googling about IE, I found that IE might get corrupted due to some unforeseen reasons... So, is there a possibility of a windows system to have NO internet explorer installed? If yes, How can I check whether IE is present or not.. Please suggest...
Thanks in Advance
|
|
|
|
|
IE is a part of Windows itself and you can safely assume its existence on Windows. I personally won't go bothering about an usecase where the IE installation is corrupt for some unforeseen reasons. It may be negligible.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Is there any way to get a XmlTextWriter to work with a MemoryStream, so that it doesn't close it when it is finished?
What I'm trying to do is:
List<T> -> MemoryStream (as XML) -> TripleDES encyrption -> file.
And later:
file -> TripleDES decryption -> MemoryStream -> List<T>
And since XmlTextWriter always closes the stream when it completes, the MemoryStream is useless!
Yes, XMLTextWriter has settings, but they are null or read-only, so you can't set "CloseOutput = false"
(No, I don't want to use XMLSerialiser, for very dull reasons!)
I have got round it by moving to XmlWriter and using the settings that way, but this was such a waste of time!
Old way:
WriteXML(listCards, new XmlTextWriter(stream, Encoding.UTF8));
if (stream.CanSeek)
{
stream.Seek(0, 0);
}
New way:
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = false;
settings.ConformanceLevel = ConformanceLevel.Document;
settings.CloseOutput = false;
settings.Indent = true;
settings.Encoding = Encoding.UTF8;
WriteXML(listCards, XmlWriter.Create(stream, settings));
if (stream.CanSeek)
{
stream.Seek(0, 0);
}
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi,
Does anyone know a way I could simulate 7.1 channel surround sound with DirectX? Our school is doing the Wizard of Oz as the school play this year, and as part of it, we want the tornado to move around the Audience, we have speakers in the right spots, and the everything we need to drive them, its just we need to be able to move the sounds around and make them feel realistic to the audience.
So in short, does anyone know how I could set up 7 listening devices in DirectSound or XNA so that the levels change for each speaker as the virtual speaker moves throughout the audience.
And here's a crude drawing of the idea: http://img30.imageshack.us/img30/3246/tornadopath.jpg[^] (each speaker group represents a different channel)
|
|
|
|
|
DirectSound does support 7.1 - set the speaker config to DSSPEAKER_7POINT1_SURROUND. (Or to DSSPEAKER_7POINT1 if you haven't gone up to XP SP2 yet.)
Then it should be just a matter of moving the sound source around the listener location, and Dorothy's your auntie...
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
Hello,
How can i open aspx webpage using c# window application?
I mean not using "System.Diagnostics.Process.Start"
but another way so i can check if there is such webpage (try...catch.. or something)
|
|
|
|
|
//in windows application there is no such thing as aspx page.
//in web application we can open a aspx page as,
Response.Redirect("Sample.aspx");
(or)
server.trasfer("Sample.aspx");
//you can open a form using windows appliaction like,
Form2 frm = new Form2();
frm.Show();
Padmanabhan
|
|
|
|
|
Yes,
But i have aspx on the net (as URL). How can i open it in browser?
|
|
|
|
|
You can do it using HttpWebResponse in the System.Net namespace.
Refer this link[^]
|
|
|
|
|
|
Hello...
I just installed USB-RS232 Device and I see in DeviceManager, that the COM Port ist 7:
"Prolific USB-COM Bridged (COM7)"
But if I try to use the COM7, the SerialPort Class throw an exception "COM Port unknown".
The COM7 is now COM1, but the text in DeviceManager is still COM7.
Has anybody the same problem ?
How to solve the problem ?
Thanks...
|
|
|
|
|
Not really a C# question hehe.
In the Device Manager, double click on your serial port to get to the settings form, then go to the "Port Settings" tab and click on the "Advanced..." button.
Here you can manually set the COM port number associated with your hardware. It usually won't update in the Device Manage list unless you unplug and plug the device again, but it will take effect immediately.
Hope this can help.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Not really a C# question
it's related to Serialport Class.
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
No, it's not. It's specific to his device and it's configuration. It really has nothing to do with C# or the .NET Framework, outside of the COM port number he's using.
|
|
|
|
|
is your port 7 is working with hyperterminal ?????
am using USB-Serial Port Driver(Prolific USB-COM Bridged (COM7)) from past 3 years , I don't get this problem till now,
check the setting again.
Note: some times Driver(usb_serial) can mal-functional, if u suspected uninstall & reinstall the driver.
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
Hi,
I am using the following code
<br />
Process pr = new Process();<br />
pr.StartInfo.FileName = "SCHTASKS.exe";<br />
pr.StartInfo.Arguments = "/Delete " + ScheduleName;<br />
when I pass the delete argument in command prompt a confirmation will appear. After pressing "y" it the schedule is deleted successfully.
I want to pass "y" as arguments but don't know how because I am already passing delete command in arguments
If any one can help me.
Regards
|
|
|
|
|
Naveed727 wrote: a confirmation will appear
There is no reliable way to do that, unless the program you are starting is rewritten to accept another command line parameter to suppress prompts.
You could try writing to the process's input stream - check out Process.StandardInput[^]
|
|
|
|
|
Hi,
I am assuming SCHTASKS is a regular console application, that produces some output (a prompt) in the console or DOS window, and takes some input from there as well.
The easy solution, if provided, is by passing another switch; try "SCHTASKS -h" to see its help.
If no extra switches are available, you should be able to do it with standard stream redirection; have a look at the Process class, StandardInput/StandardOutput properties, and OutputDataReceived events. You probably need to redirect the output (so you can wait for the confirmation prompt to arrive), AND redirect the input stream, so you can writeline "Y" to it.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
If internet explorer is opened and a url which ends with .pdf is opened, then how can I catch the information regarding PDF file which is viewed in browser.
Are there any API's in windows regarding to get the info about PDF file which is opened in browser?
|
|
|
|
|
You can use Request.Browser[^]
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|