|
Try to re-phrase your requirement. What do you want to do:
- Send an email to a freshly created user / someone else
- Use a template for the email
- Have the user edit the email before sending it
- Send it without Microsoft Outlook (SMTP)
- Download a file (why?)
- ...?
|
|
|
|
|
They just want to be able to track the sent emails through the shared email that they are using for support here. That is why I need to be able to download the email and have it open in Outlook. All of this code is handled in the Admin section of the website. The admin users are the ones who would download and send the new user emails out.
Bernhard Hiller wrote: Try to re-phrase your requirement. What do you want to do:
- Send an email to a freshly created user / someone else
- Use a template for the email
- Have the user edit the email before sending it
- Send it without Microsoft Outlook (SMTP)
- Download a file (why?)
- ...?
|
|
|
|
|
Hello there. Does there exist a way to execute my C# code (either graphic or non-graphic) on GPU (I have nvidia's gpu)?
1 - There exists this CUDAfy.Net from codeplex but I think I would like to do something that is directly done through visual studio. What could I do for this?
2 - What would be the best possible approach if I want to use Direct3D API from C# and get that code executed on GPU ?
Thanks for any input or pointer?
This world is going to explode due to international politics, SOON.
|
|
|
|
|
|
First one can definitely be executed on GPU. Can the second one be run on it as well?
What can you say bout SharpDX and SlimDX?
This world is going to explode due to international politics, SOON.
|
|
|
|
|
AmbiguousName wrote: What can you say bout SharpDX and SlimDX? They're wrappers around DirectX. I don't have a 3D-card, but Warcraft is happy with DirectX.
What do you plan to (ab)use the GPU for?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: What do you plan to use ( ) the GPU for? Still learning graphics programming (you might have noticed). Just want to know that GPU can be used for general purpose processing. You did't answer the question. Can I make my GPU run the:
- Direct3D code using C#
- SharpDX code
- SlimDX code
This world is going to explode due to international politics, SOON.
|
|
|
|
|
AmbiguousName wrote: Just want to know that GPU can be used for general purpose processing. You can't use it as a second CPU, can't simlpy tell a new thread to run on the GPU; it doesn't do general processing, but works magic with large numeric datasets.
AmbiguousName wrote: You did't answer the question Kind of did
You're not going to program directly against the driver of the graphics-card, but against the next-best abstraction layer. That's DirectX.
SharpDx and SlimDx are wrappers around DirectX - they'll make it easier to have the GPU do something from C#, but will (probably) not offer everything that DirectX itself offers.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
foreach (var fname in fnames)
{
string[] lines = File.ReadAllLines(fname);
for (int i = 0; i < lines.Length; i++)
{
string[] wordsInLineRaw = Regex.Split(lines[i], @"\W+");
string[] wordsInLine = new string[wordsInLineRaw.Length];
for (int p = 0; p < wordsInLineRaw.Length; p++)
{
wordsInLine[p] = wordsInLineRaw[p].ToLower();
}
for (int j = 0; j < wordsInLine.Length; j++)
{
string w = wordsInLine[j];
if (stopWords.Contains(w)) continue;
if (!index.ContainsKey(w))
{
if (worker.CancellationPending)
{
}
index.Add(w, new IndexEntry());
}
index[w].UpdateInfo(fname, i);
}
}
|
|
|
|
|
There are a number of ways you can approach this.
The simplest is to execute the body of your outer loop for multiple files at the same time. You can use the Task Parallel Library that is part of .Net for this. The 'Task' classes let you run code in parallel and wait for results at the end.
If you choose to do that, the problem is now "How do I merge results of concurrent indexes into one big index"
Some possible solutions are:
- Use a lock to protect access to the index
- Create separate indexes and merge them at the end.
I would go with the second because it uses less shared state, and has less chance of me introducing a difficult to find bug
var indexFilesTasks = (from fname in fnames
select Task.Run(() => IndexSingleFile(fname, stopWords, () => worker.CancellationPending))).ToArray();
Task.WaitAll(indexFilesTasks);
index = MergeIndexes(from t in indexFilesTasks
select t.Result);
The IndexSingleFile() method contains all your code in your foreach (var fname in fnames) loop.
The MergeIndexes() method takes multiple Dictionary<string,indexentry>() structures, and merges them together. Below is the code I used for these.
Note this isn't the "best" way, but just one way of approaching the problem.
Dictionary<string,IndexEntry> IndexSingleFile(string filename, HashSet<string> stopWords, Func<bool> isCancelling) {
var index = new Dictionary<string,IndexEntry>();
string[] lines = File.ReadAllLines(filename);
for (int i = 0; i < lines.Length; i++)
{
string[] wordsInLineRaw = Regex.Split(lines[i], @"\W+");
string[] wordsInLine = new string[wordsInLineRaw.Length];
for (int p = 0; p < wordsInLineRaw.Length; p++)
{
wordsInLine[p] = wordsInLineRaw[p].ToLower();
}
for (int j = 0; j < wordsInLine.Length; j++)
{
string w = wordsInLine[j];
if (stopWords.Contains(w)) continue;
if (!index.ContainsKey(w))
{
if (isCancelling())
{
}
index.Add(w, new IndexEntry());
}
index[w].UpdateInfo(filename, i);
}
}
return index;
}
Dictionary<string,IndexEntry> MergeIndexes(IEnumerable<Dictionary<string,IndexEntry>> indexes) {
var result = new Dictionary<string,IndexEntry>();
foreach (var index in indexes) {
foreach (var srcPair in index) {
if (!result.ContainsKey(srcPair.Key)) {
result[srcPair.Key] = new IndexEntry();
}
result[srcPair.Key].MergeFrom(srcPair.Value);
}
}
return result;
}
modified 12-May-14 4:49am.
|
|
|
|
|
Phil Martin wrote: The simplest is to read in multiple files at the same time Wow, where do you get such multi-tasking harddisks from?
No, seriously: that step is likely to be the slowest of all, hence hardly anything can be gained from parallelizing. Only when processing the file contents takes a relatively high timespan, parallelizing might help, but then I'd uncouple reading and processing (i.e. read the file into memory and then send it to the processing function, with the next file read being started at that moment - note: may require large memory). The locks on the index may cause some extra overhead, i.e. slow down again.
|
|
|
|
|
I'm not sure Phil meant to read the files in parallel then continue processing them on a single thread. By parallelizing at the top level, the thread reading the file goes on to processing it so I'd say his assertion was correct but probably better stated as 'read in and process multiple files at the same time'.
It's an odd thing to do anyway. If I were to try and improve the performance of this code the first thing I'd do is get rid of the ReadAllLines and switch to streams before even thinking of going parallel.
Regards,
Rob Philpott.
|
|
|
|
|
Thanks for clarifying that for me Rob. And I agree with you, there are many other things I'd do first and differently. I was aiming for minimum effort on the developer's part with minimum side effects.
I'll edit the post and try to be a little less ambiguous about my intent.
|
|
|
|
|
Ha! I wish I had multitasking hard disks!
My choice of wording was poor, and I hope the code clarified the intent, i.e. choosing the simplest point in the original code to parallelize. Will the changes be optimal? No. Will they be parallel with significant and measurable difference? Yes.
And yes, there are many other options, but I think this was one of the simpler approaches to understand. If they already understood ways to set up a dataflow to achieve the task, I'm pretty sure they would have already done it that way.
|
|
|
|
|
Minimum changes would have been to just use Parallel.For on the outer loop and switch to a ConcurrentDictionary or use locks around the regular Dictionary. Your overall solution is overly complicated (no offense). Any time you save by parallelizing the main loop will be destroyed (and then some) by the merging loop.
|
|
|
|
|
Thanks for taking the time to reply. And I agree, parallel.for would have been the least invasive. And no offense taken!
|
|
|
|
|
Hi! First, I am totally new in programming, so excuse me if I ask dumb question.
I am trying to make a new project in Visual Studio. I have Northwind database installed (probably came with VS installation). It is in Sample folder.
In my project I need to use stored procedures from Northwind database and also to make one new stored procedure. I managed how it's working, but I can't do it. I connected to the database, but it's not showing me that I have any stored procedures in it, in Database explorer.
Any ideas?
|
|
|
|
|
Well, if you're using Sql Management Studio, make sure you refresh the Object Explorer. This isn't clever enough to update by itself if you are expecting it to do so.
Regards,
Rob Philpott.
|
|
|
|
|
what is your code can you show here
Sankarsan Parida
|
|
|
|
|
I have a question about plotting data from database to a line grpah. In my line graph there is 3 data that is tempin, tempout and also humdity that I must plot in a line graph..I made this coding but it seem doesn't work.I have a sql statement to selesct data but I do know how to plotting the line in a graph. Can anyone help me?
string sql = "SELECT TempIn, tempOut, humidity FROM Environmnets WHERE DateT > DateADD(mi, -30, Current_TimeStamp) INNER JOIN TDevice ON Environmnets.Deviceid = TDevice.id INNER JOIN TMushroomHouse ON TDevice.MushroomHouseId = TMushroomHouse.id WHERE TMushroomHouse.id = @id";
using (SqlConnection con = new SqlConnection(strConnString))
using (SqlCommand cmd = new SqlCommand(sql, con))
{
cmd.Parameters.AddWithValue("@id", DropDownList1.Text);
con.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
TempInTextBox.Text = dr.GetValue(0).ToString();
TempOutTextBox.Text = dr.GetValue(1).ToString();
HumidTextBox.Text = dr.GetValue(2).ToString();
Chart1.Series["TempIn"].Points.AddXY(DateTime.Now.ToShortTimeString(), Double.Parse(TempInTextBox.Text));
Chart1.Series["TempOut"].Points.AddXY(DateTime.Now.ToShortTimeString(), Double.Parse(TempOutTextBox.Text));
Chart1.Series["Humidity"].Points.AddXY(DateTime.Now.ToShortTimeString(), Double.Parse(HumidTextBox.Text));
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
}
con.Close();
|
|
|
|
|
There's not much to go on here.
Is your chart emtpy or do you get an error? What is the error? Did you debug and step through to find where it goes wrong?
Is the SQLDataReader filled after the statement is executed?
This Chart1 object, what is it? A library? Where there samples where you found the library. Some documentation? Do those samples work?
Also make sure to split business logic from fetching data...
|
|
|
|
|
<asp:Chart ID="Chart1" runat="server" Height="339px" Width="896px"
Chart1 is a Chart ID. Actually there is no error, but the graph is not display line graph as what I want. It will display all data in database but I just want to display data from 30 minutes only. Do you know in this forum there is function to attach picture? so u can see clearly what I want to explain.Tq
|
|
|
|
|
You cannot attach pictures, but you can upload one to an online repository (like flickr or something) and provide the link.
If you execute the SQL to the database directly, is the resultset correct?
If that is correct, debug and check if the resultset in your application is correct. If the graph is showing and drawing, the culprit is most probably getting the data.
|
|
|
|
|
The SQL is wrong. When I execute the SQL to the database, no result will show. I will try to attach the picture for you
|
|
|
|
|
Syafiqah Zahirah wrote: TempInTextBox.Text = dr.GetValue(0).ToString();
TempOutTextBox.Text = dr.GetValue(1).ToString();
HumidTextBox.Text = dr.GetValue(2).ToString();
Chart1.Series["TempIn"].Points.AddXY(DateTime.Now.ToShortTimeString(), Double.Parse(TempInTextBox.Text));
Chart1.Series["TempOut"].Points.AddXY(DateTime.Now.ToShortTimeString(), Double.Parse(TempOutTextBox.Text));
Chart1.Series["Humidity"].Points.AddXY(DateTime.Now.ToShortTimeString(), Double.Parse(HumidTextBox.Text));
Why do you send the values from the database to textboxes, and then parse them from the textboxes to numeric values again?
What about
double tempIn = dr.GetDouble(0);
Chart1.Series["TempIn"].Points.AddXY(DateTime.Now.ToShortTimeString(), tempIn);
And since you always use DateTime.Now on the x axis, I think you are missing something else. What about querying the DateTime value also from the database, and using it here instead of DateTime.Now?
|
|
|
|