|
Well, using Sleep in a UI thread is a nuisance to the user because it blocks interaction.
In this case, being a background service (no UI), it's not a bad way to go.
Unless you can get rid of the necessity of periodically polling for changes in you database, you must release the processor. You seem to use a busywait loop which utilizes the CPU to its capacity doing nothing at all (most of the time).
Alternatively you could try some sort of timer.
Cheers
I don't like my signature at all
|
|
|
|
|
I Don't think you have any while loop problem. The problem could be that connecting with SQL Server 2000 Database. At the initial state it takes (connecting with SQL Server 2000) long time bcoz sql server is just starting. Try finding to sql server running state and then connect with that. Sleep is not an good idea.
|
|
|
|
|
Hello everybody,
this might sound like a simple question, but after searching more information on the web I couldn't find any useful stuff. Maybe someone here knows the approach to use?
I have a picturebox in which I load an image in "normal" mode (the image is supposed to keep its original size). The image will always be aligned on the left side of the picture box... BUT I NEED it right-aligned! Is there a (simple) way to do this, e.g. like a "dockmode" to dock the image to one side of the picture box? The "normal" mode seems to place the image to (0;0) coordinates by default - is there a way to change that default behaviour?
Thank you
Michael
modified on Wednesday, May 26, 2010 1:36 PM
|
|
|
|
|
Possibly resolved...? I just don't know if that's the most elegant method, also considering performance issues...
Here's how I'm currently doing it:
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If PictureBox1.Image IsNot Nothing Then
Dim g As Graphics = e.Graphics
g.DrawImage(PictureBox1.Image, PictureBox1.Width - PictureBox1.Image.Width, 0)
End If
End Sub Any hints or constructive criticism around ?
|
|
|
|
|
Unless you have a really compelling reason to use a PictureBox you could perform the same trick with, for example, a Panel .
The reason that I say this is that in my experience the PictureBox Control is evil, evil I tells ye. Every time I have tried to use one, somewhere along the line it has snuck up behind me and taken a very large chunk out of my backside.
Just my opinion.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
I wouldn't go as far as calling it evil, however it is pretty useless. Ask it very simple things (the ones you could do yourself in less than 5 lines of code), and it will do most of them well. Like showing a picture (and nothing else actually). Have a serious requirement? first thing to do is throw away the PictureBox.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I have never tried this, but IMO it should work: set the SizeMode to auto, put the PictureBox inside a Panel, and choose a top right Anchoring.
Of course, KISS adepts, myself included, recommend a simple Panel with a paint handler.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thank you guys for the confirmation about the code and the hint about using a panel.
After trying the approach of directly painting onto the panel I have to say that the approach has some major tradeoffs in my case, especially because my picturebox sits fully-docked in the upper part of a SplitPanel (vertical split), which doesn't have a separate paint event. As a consequence I'd have to use the paint event of the whole SplitPanel, which's PaintEventArgs obviously delivers a different e.graphics than the picture and results in funny effects. I didn't dive deeper into solving this, assuming your idea was meant to make my coding easier - so I made friends with the Picture Box .
Sometimes it's funny: You just don't consider (and call) it "evil" and it behaves like a puppy
|
|
|
|
|
Hi,
(.net 4, VS 2010 express)
I have a windows form with a DataGridView, a dataset, a timer, and a boolean variable (GUI thread).
I have a separate thread where I fill another dataset, created in that thread (data thread), when this thread has filled its own dataset I set the boolean to true.
At the timer tick event, in the GUI thread, I check the boolean. If it is true, I copy the data thread's dataset to the GUI thread's dataset (MyGUIThreadDataSet = MyDataThreadDataSet.Copy ).
Then I attach the GUI thread's dataset to the DataGridView (DataGridView.DataSource = MyGUIThreadDataSet ).
When I run the application, the line DataGridView.DataSource = MyGUIThreadDataSet causes a cross thread error.
What am I missing here?
Cheers,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi Johan,
did you already try the standard method using a delegate? It's commonly used to avoid cross-thread trouble... This is an untested example - just an idea:
Public Delegate Sub CopyDelegate(ByVal e As CopyEventArgs)
Public Sub UpdateGui(ByVal e As CopyEventArgs)
If InvokeRequired Then
Dim dlg As New CopyDelegate(AddressOf UpdateGui)
BeginInvoke(dlg, New Object() {e.arg1, e.arg2})
Else
' put everything to happen on the GUI here
DataGridView.DataSource = MyGUIThreadDataSet
End If
End Sub Hope it helps
Michael
modified on Wednesday, May 26, 2010 12:18 PM
|
|
|
|
|
This is what is needed. The only thing I would note is that you need to make sure the number of parameters and the type of the parameters match.
BeginInvoke(dlg, New Object() {e.arg1, e.arg2})
won't work because CopyDelegate only takes one parameter and it's the same type as what UpdateGui takes (as it has to be). I believe it should just be
BeginInvoke(dlg, New Object() {e})
Also, you will want to specify which object the InvokeRequired is coming from...as in
If DataGridView1.InvokeRequired Then
...
DataGridView1.BeginInvoke(...)
|
|
|
|
|
Thank you guys both for your help.
Cheers,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Below is a small macro wot I just wrote...
I want, at the click of a macro, to create a New Sheet, then to go the previous sheet (ie the one for the previous month) and pick up and copy the framework.
I do not want to pick this sheet up by name, for each month will have a different Carry Forward (CF) value.
So I want to pick up the CF from always the previous months sheet.
I tried Sheets(Sheet.Count(-1)).Select but it is throwing me out at this point.
Any ideas?
Sub NewMonth()
'
' NewMonth Macro
'
' Add sheet
Sheets.Add After:=Sheets(Sheets.Count)
' Copy previous month
Sheets(Sheet.Count(-1)).Select
Columns("A:J").Select
Selection.Copy
Sheets("Sheet1").Select
Range("A1").Select
ActiveSheet.Paste
' Last months CF
Range("H40").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=+Sheets(Sheets.Count(-1)!R[2]C"
' Month Header
Range("E1").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
Range("E1").Select
Selection.Copy
Range("E1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
Sheets(Sheet.Count(-1)).Select must be
Sheets(SheetS.Count(-1)).Select
|
|
|
|
|
DOH!!!!!
Yes, obvious now!
I can't believe I missed that!
That one goes into the "Did I really do something that stupid? Ah, I see I did' Folder.
Thanks!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
|
Sheets(Sheets.Count() - 1).Select
|
|
|
|
|
As my response above, missed something obvious, so that was two bleedin' obvious things in one damn line.
I am having a bad day!
Cheers.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
If that classifies as a 'bad day' i don't know what my 'bad day' should be renamed............
Anyway, you MUPPET!
|
|
|
|
|
daveauld wrote: Anyway, you MUPPET!
Guilty as charged!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
I want to binary serialize a class, which has only shared items (variables & objects of different types) which I use globally in my code.
When I want to serialize it, I get the error "'EmailAccount' is a type and cannot be used as an expression" :
binformatter.Serialize(filstream, EmailAccount)
I even tried to create an object from the class and serialize it. But it seems to only save the instance variables and not the shared ones.
Is there a way to serialize them?
|
|
|
|
|
Serialzation only works on instance members. Shared, or static in C#, members are not part of any instance. You'll have to either save them sepearately or there are various methods of including the static members in the serialization, but they will be included in every single instance of the class you serialize. One method would be to create public "wrapper" properties for the shared members.
|
|
|
|
|
hi mates,
how will I use Enter key instead of Space key to check the checkboxes in datagridview? Note: checkbox is inside the unbound datagridview.
thanks in advance
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
Personally, I'd find the different behavior confusing. But, you could change the checked state in a KeyPress event or similar.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
my project only needs calculator keypad. thats why i only use specific key such as enter key. actually i have keypress event but checkbox value sometimes does not effect. heres my code snippet.
If e.KeyChar = Keys.Enter Then
If Me.C1grid.Col = 5 Then
Me.C1grid.Columns("IsOut").Value = CInt(Not CBool(Me.C1grid.Columns("IsOut").Value)) * -1
Me.C1grid.Columns("IsIn").Value = CInt(Not CBool(Me.C1grid.Columns("IsIn").Value)) * -1
End If
End If
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|