|
If it's only 50 records you should parse and read the entire file into a List<Record>, where a Record is a data holding class which is populated in a similar way to your code here, at the start. Working with a proper domain object with properties is much better than working with a string format the whole time.
To read all the records you do something like
List<Record> GetRecords(string s){
List<Record> r = new List<Record>();
ReadHeader(s.Substring(0, HEADER_LENGTH));
s = s.Substring(HEADER_LENGTH);
while(s.Length > 0){
string recordstr = s.Substring(0, RECORD_LENGTH);
s = s.Substring(RECORD_LENGTH);
Record rec = new Record();
rec.CO_ID = recordstr.Substring(0, 5);
r.Add(rec);
}
return r;
}
ed: HEADER_LENGTH = 463 and RECORD_LENGTH = 276.
|
|
|
|
|
I'm trying to have a timer countdown and once it reaches 0 it would move a value from one gridview to another. The build crashes once it reaches 0 and says something about not being able to change controls on different threads. I did some research and they say I need to Invoke? or create a BackgroundWorker?
System.Threading.Timer timer;
int time = 30;
timer = new System.Threading.Timer(new TimerCallback(timerCallback),
null, 0, 1000);
public void timerCallback(Object obj)
{
else
{
timer = 0;
moveToGrid(grid1, grid2);
}
}
The moveToGrid method works fine if I put it in an onClick event but the build crashes when put as shown above. Can anyone point me in the right direction?
|
|
|
|
|
You are going to have to check if invoke is required in the moveToGrid method, something like this:-
void MoveToGrid(DataGridView grid1, DataGridView grid2)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(() => MoveToGrid(grid1, grid2)));
}
else
{
}
}
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
That worked great! Thanks a bunch. At first I didn't think it was going to work because the way I have it set up. Just had to check if invoke was required on two separate methods and worked like a charm.
|
|
|
|
|
Glad to help.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
You may want to read this article[^] on GUI Controls and threads.
The easiest approach could be using the right timer: Windows.Forms.Timer s tick on the GUI thread...
|
|
|
|
|
Yes, for this sort of purely UI related thing I recommend using the Windows.Forms.Timer. It is less accurate, but on a level that you don't care about, and its events go through the normal UI thread message queue.
|
|
|
|
|
I'll have to look into this then. Still learning so anything new is good.
|
|
|
|
|
The timer is being executed on a separate thread, no you didn't create one, it was done for you by the Timer object, but the UI can only be updated from the main thread. You need the Invoke to call the main UI thread and update the grids, as Wayne responded.
No comment
|
|
|
|
|
Respected Sir,
Sir tell me the Way that How I can Create Classic Menu in C# desktop apll. Which fell like flash, & application become attractive - Devdatta
|
|
|
|
|
Umm... what? You want a MainMenu (like I do)?
Either add it dynamically or add it to the toolbox (if using VS or whatever).
For VS: right-click the toolbox, select add items (or whatever it is), find the Main Menu, select it.
|
|
|
|
|
hi im building a app for dtg printers to print a white underbase i have built the app in c# i no a bad choice for photo editing but time is the key here
bassicly what i need atm i have a button to invert a png and change the contrast so it changes the hole image to black what im looking to do is to shrink the pixels of the end of the image by one pixel all the way around the image btw its a transparent png so only the vissible pixxels need reducing
i hope you can understand this
|
|
|
|
|
Member 7738561 wrote: i hope you can understand this
You could help that by not using txtspk.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Peter_in_2780 wrote: You could help that by not using txtspk.
...or by using punctuation.
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Are you speaking of a situation in which you have a png file with transparency: and you want to produce, for multi-color printing, a separation plate that contains all the 'transparent' pixels in the .png file, with the idea that those transparent pixels will be rendered in white on that plate ?
And then you want to trim the boundaries of that plate only ?
Even if that is the scenario you describe here, it doesn't make a lot of sense to me. By the way, I've written color-separation software for Adobe products in the past, and am quite familiar with what's involved with complex color-separation scenarios involving both CMYK plates, and spot-colors, custom varnish overlay plates, etc.
best, Bill
"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone." Bjarne Stroustrop circa 1990
|
|
|
|
|
I am referring to commenting out a section within a line using block comments like this:
Console.WriteLine(((x + y) / 2));
Is there a keyboard shortcut or quick way to do this? I tried to highlight it and select "surround with", but I didn't see any options for comments.
I also know there is the CTRL+K, CTRL+C shortcut, but this comments the entire line and not just the small selection I have highlighted.
I'm using a vanilla install of Visual Studio 2010 with no add-ons.
Thanks all.
|
|
|
|
|
You can create your own snippets. Create a new file in VS (from the File menu, New, XML file is fine.)
="1.0"="utf-8"
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>CommentBlock</Title>
<Shortcut>CB</Shortcut>
<Description>Code snippet for Comment block</Description>
<Author>Microsoft Corporation / Paul Griffin modified</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>comment</ID>
<ToolTip>comment block</ToolTip>
<Default>MyComment</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets> Save the file in the folder:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C# As CommentBlock.snippet
It will now appear in the Surround With list for C# files.
It's a bit rough and ready - it's the first one I have done - but it works.
[edit]Typos in the introduction text - OriginalGriff[/edit]
[edit]I have re-worked this a little, and posted it as a Tip/Trick: Adding a Snippet to Visual Studio[^] - OriginalGriff[/edit]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
modified 16-Nov-11 6:12am.
|
|
|
|
|
Wow, Griff, thank you SO much, that is Awesome!!!
It worked perfectly - just like you said and I've got it all set up now and everything.
Seriously, thank you VERY much.
|
|
|
|
|
Griff's answer is excellent, I'm just surprised that the 7 keystrokes you'd need to do that right now (slash, star, ctrl+right 3 times, star, slash) annoyed you enough to want to find a shortcut.
|
|
|
|
|
You mean 10 keystrokes. A "star" is Shift + 8 which is 2 keystrokes, and you forgot to count the CTRL keystroke, though I only counted it once since I could hold it down.
And that's just to comment out a simple Math.Truncate phrase. If I were doing a much bigger section of a line or even multiple lines, the keystrokes could exponentially grow.
Thanks for the Ctrl+right tip though, I didn't know that either and I like it.
|
|
|
|
|
Consider the following example..
public class Student
{
public string Name { get; set; }
public IList<Course> Courses { get; set; }
}
public class Course
{
public string Name { get; set; }
public IList<Student> Students { get; set; }
}
In this example a circular dependency exists between Student class and Course class. The scenario arises when we are dealing with entity framework - wherein db tables are created as classes for a Student database management system.
In case of C++ we use the concept of forward declaration for telling a class 'A' that another class called 'B' exists even before defining the class 'B'.
Can anybody explain how C# compiler solves this problem of circular dependency between classes?
PS: Please avoid telling me that the classes sould be redesigned to avoid circular dependency. The question is not related to designing since the below mentioned classes are very much from day-to-day programming scenarios.
If asking a question is bad; then not knowing the answer is worse!
|
|
|
|
|
With Interfaces.
public interface IStudent { String Name ... } ;
public class Student : IStudent
{
public string Name { get; set; }
public IList<ICourse> Courses { get; set; }
}
public interface ICourse { String Name ... } ;
public class Course : ICourse
{
public string Name { get; set; }
public IList<IStudent> Students { get; set; }
}
Or something like that.
|
|
|
|
|
I am by no means an expert, so don't take this answer as gospel. I am posting more to see if the gurus out there will correct any bad assumptions I have.
As I believe: C++ is based on C. When C was created there was a need to keep compilers efficient - CPU time = $$$$. Therefore, the C language was designed with the idea that its compilers should not need to make multiple passes of the code. In a single-pass compiling strategy, you have to know what something is before you can use it. Hence procedures and variables had to be declared before they could be used. That led to the need for header files and forward declarations.
I don't know if C++ compilers really need forward declarations, or whether it was just a carry over from C. But either way, this why I believe C++ has header files too.
C# simply broke the tradition. If you allow your compiler to go over the code once and categorize the classes/methods/properties/fields and then go over it again to compile it, then there is no need for forward declaration, nor for header files.
Am I way off base, Gurus?
Clive Pottinger
Victoria, BC
|
|
|
|
|
That's right; Eric Lippert explained it in more detail on his blog[^]
|
|
|
|
|
Ah!! Multiple parsing is the secret!!
Thank you very much Clive for answering my question and thank you Harold for sharing that wonderful link.
|
|
|
|