|
Do not cross post.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Hello.
I am fairly new to C# programming, (I am trying to teach myself), and I would like to know how to make custom (either WinForms, or WPF) components.
The components that I am trying to make need to be fairly efficient, as I want to repaint them at least 30 times a second (with new data to display each time).
I am fine with using unsafe code blocks if they are needed.
The data that is going to be displayed is in the form of 1-dimensional HSL (Hue Saturation Luminescence) pixel data.
I want to show a moving display of this data, a graphical FIFO stack (one that discards the first inputs upon overflow).
Working on a digital signal processing article.
(My first article on this site)
|
|
|
|
|
There are two parts to this question. You don't actually need very much for a custom control if it is simply output, and in fact I'd be tempted just to use a PictureBox and catch Paint. The correct way to do it though would be to inherit from UserControl and override OnPaint. There's some information about how to write general custom controls in my LineEditor article[^] (scroll about half way down), but you probably don't need the user input parts.
The second part is how to draw a 1 dimensional data series (if I'm understanding you correctly, that's just a stripe of pixels?) quickly. 30 fps still gives you 30ms per frame, though you don't want painting to take all of that (obviously), so my gut feeling is that you can just paint normally, with Graphics.FillRectangle, but it depends how many pixels are visible at once. If that is too slow, use one of the fast ways of mucking with bitmap data (a search for Bitmap.LockBits here on CP should find them) to put the frame data into a temporary buffer and then use Graphics.DrawImage to copy it to the control during the paint phase.
|
|
|
|
|
Thanks!
Yes, you did understand the second part correctly.
I have a sensor that is supplying data over ethernet that needs to be displayed on the screen.
It reports intensity in HSL values, one strip at a time, kind of like a flatbed scanner.
I am making a GUI element that displays this data in a waterfall like display (thus the FIFO stack).
Working on a digital signal processing article.
(My first article on this site)
|
|
|
|
|
I would like to learn C#, I have been doing C++ for a while. What is a good meaningful project that I can work on to learn lots of C#, like SQL db, basics of C# and webservices if possible, all in one project. I can do like a banking exxample, but can anyone suggest a more meaningful project?
|
|
|
|
|
It depends on what you really want to learn. I believe there's no such thing as all-in-one project. A lot of developers are excited to jump into the advanced topics without getting familiar first with the basic ones. IMHO, I would advice you to start by writing some simple data entry application when you want to learn C# and SQL. That way, you get to familiarize yourself with the syntax.
Signature construction in progress. Sorry for the inconvenience.
|
|
|
|
|
|
First you need to narrow your focus quite a bit, what interests you (not what you think will make you the most money), look at the different types of application that can be built. Tools, communications, LOB, new media, social crap, web, desktop and many more. The requirements for each are dramatically different.
Example: I do LOB work and would not a accept new media contract as I have no expertise in that area.
Once you have an area defined then pick a subject that you have some knowledge about, or find a sponsor who is willing to share their knowledge. Now you can start work.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I find a number of code samples and quick starts available on msdn. They should get you help started.
|
|
|
|
|
Firstly: don't! Trying to learn everything at once is a certain recipe for disaster.
Secondly: Decide what you need to learn and then prioritise those needs and approach them one at a time. You say that you are new to C# programming so that is the obvious place to start. .NET Book Zero[^] by Charle Petzold is a great place to start. You can follow that up by the C# Tutorials[^] on MSDN, and also lots of samples in the CodeProject Articles[^] section. Once you are comfortable with the language you can move on to SQL[^] and perhaps ASP.NET[^] depending on what you plane to develop.
|
|
|
|
|
A web application of some kind is good for getting a cross-section across the various technologies. A book I used to learn PHP/mySQL did an online wine store (minus the actual interface to a payment provider which is not particularly instructive and rather tedious). You could write a simple social networking site (Facebook/LinkedIn/etc) or a microbroadcast site (a la Twitter), but be sure not to set your sights too high trying to create something similar to a multi-million dollar commercial enterprise – you'll just burn out.
|
|
|
|
|
Develop any MIS as Hospital Management System, Student Information System etc.
|
|
|
|
|
Thanks all, great answers. Some of you suggested to brush up on my C#, I actually have. I have read all the basics of the C# language, thats why I was looking for some project to get into and apply the principles that I know. Talkingto SQL database is always similar to other languages, no big deal. I didn't want to learn all aspects in details, just do something simple with webservces, WCF..etc to know how it works for the most part.
Someone suggested a hospital or student Information system, I think either one is a good example.
Thanks again
|
|
|
|
|
Hello,
I have been digging on this topic for several days now, and cant seem to get started... Any advice is appreciated.
I have an application that outputs its log files to a txt file. I would like to write an app that can monitor that txt file for a keyword. Once that keyword is written to that log file, my app will send me an email notification.
If that keyword is appended to the log file, and I am successfully notified, I dont want the app to keep notifying me. Just one time per event.
I could do this in linux with tail -f, but am unsure how to complete this task in windows with C#...
I am currently using FileStream/StreamReader to search my text file for the keyword, and that works. But it keeps scanning the entire text file and keeps notifying me. I would just like it to read lines that are "new".
Thanks for any ideas... Would love to get started on this project...
Currently I am using this code found on codeproject forums:
<pre lang="c#">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DirectoryInfo dirInf = new DirectoryInfo(@"C:\Program Files\Temp");
FileInfo[] files = dirInf.GetFiles("*.txt");
foreach (FileInfo currentFile in files)
{
FileStream fs = new FileStream(currentFile.FullName, FileMode.Open);
StreamReader reader = new StreamReader(fs);
string fileContent = reader.ReadToEnd();
if (fileContent.Contains("Failed"))
{
MessageBox.Show("The File " + currentFile.FullName +
" Contains the text your searching for");
}
fs.Flush();
reader.Close();
fs.Close();
}
}
}
}
modified 25-Sep-11 15:34pm.
|
|
|
|
|
Hi,
1.
the cleanest approach would be to adapt the producer, which could not be acceptable or doable at all.
2.
the best approach on the consumer side depends on how (and how long) you want to run this. It could either be a utility that runs periodically, or an application that runs all the time and has a big delay (Thread.Sleep) or timer built in. If it is to run independent of a user being logged in, it better be a Windows Service.
3.
You need to remember how long the files were the last time you inspected them, and then only inspect whatever has been added to them. For a periodical utility this requires external storage (maybe an XML file), for a continuous app a mere Dictionary<string fileName, long fileLength> could do.
4.
You are currently reading the entire file; rather than using StreamReader.ReadToEnd , you could have used File.ReadAllText or File.ReadAllLines . However, if the observed app runs for hours or more, the log files could grow into the MB or GB, so that would not be practical. The latter two return the whole file, whereas the former returns anything from the current position to the end, so what you should do is use StreamReader.Position and StreamReader.ReadToEnd .
5.
BTW: there is no need for fs.Flush(); , and this for two reasons: (a) the file is being read, not written, so there is no dirty data anywhere; and (b) it is followed right away by an fs.Close(); , which always takes care of dirty data.
6.
There might be a slight chance that the things you are looking for get straddled over the "old" and the "new" log file (as in the log first ending on "Fai", then "led in some method" being appended); so it would be wise to back up a little when restoring the most recent position.
HTH
|
|
|
|
|
Thanks for the heads up...
This log file is only going to be about 1mb at max. During the day, I keep an eye on the log file. When I leave work for the night, I would like to be notified if the word "Failure" is written to the log. At the end of the week, the job is over and the log will be cleared and start all over on Monday.
|
|
|
|
|
you're welcome.
|
|
|
|
|
Good answer. I was going to mention the storage of the last location (or the end of the last complete line, most likely, for a log file, another way of saying your 6) and just reading from there.
|
|
|
|
|
Here's an idea:
1. in your monitoring class keep a class-instance-scoped (or static ?) variable that maintains the index in the log file where the last instance of 'failed' was seen.
public int lastFailIndex;
2. on notification:
a. read in the file, as you do now
1. get the index of the last instance of the string 'failed'
int currentFailIndex = fileContent.LastIndexOf("failed");
2. compare to stored Index
if(currentFailIndex > lastFailIndex)
{
lastFailIndex = currentFailIndex;
}
2. another simple remedy to see if the file has changed at all would be to store the length of the string created by ReadToEnd, and compare each time to see if the file has become larger: of course, you may know the log file, inherently, will be larger each time you open it, in which case: forget about that.
But, it's more interesting to think a little "out of the box" here:
1. if your log-file is delineated by lines (carriage returns and/or linefeeds) you could use File.ReadAllLine(/filepath/) to return an array of strings, and then work backwards from the end of that array to see if you have a new instance of a "failed."
In this case the 'Count property of the string array could be preserved to test for file change ?
For discussions on other (more elaborate) techniques to read a file from the end, and even a code example from Master Jon Skeet himself, check out[^].
best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
On a previous job, I had to do something similar with a log file created by a third-party product (but storing the data in a database). I wrote a Windows Service that did it.
When the Service cycled, it read the last Position from the database, opened the file, set the Position and continued reading. I had to be sure that only complete lines were processed, so I read one character at a time and considered a line to begin with a linefeed and end with a carriagereturn. Upon reading the carriage return, the line would be processed and the Position stored in the database. If the end of the file was reached, the cycle stopped. Processing over midnight was a little problematic because the previous day's file (which might not have been completely processed yet) was renamed and a new log started.
|
|
|
|
|
In the last few days I decided to create a new dictionary application, I searched the internet for how to implement database files and search algorithms but I found nothing
If you have any idea about how dictionaries are created and how a its database files are structured, please help !!
<b>Note: I don't want to use DMS (data base management system) like MS SQL server or MySql, I just want to use text files or custom format file</b>
|
|
|
|
|
A regular dictionary with words and meanings? Or a spell-check dictionary (no meanings)?
Back in college (late 80s), one of the assignments was to implement a spell-check dictionary. For that, the words were stored in a text file, but read into a special structure. I suppose it could be extended to include a meaning too.
Either way, today I'd just stick with a database. In fact a few years back I wrote a simple Scrabble word checker application -- currently it uses an Access database.
|
|
|
|
|
Check out the following links:
http://www.dotnetperls.com/dictionary
http://www.dotnetperls.com/word-search
|
|
|
|
|
Please make your links into clickable links.
|
|
|
|
|
Thanks it helped
|
|
|
|
|