|
Thanks to Nick's suggestion Nick Butler wrote: Derive from Socket and override Dispose. .
I managed to find the fault when I overrode Disconnect and had it dump a stack trace.
The previous version of this service used WSE, the new version of this service uses WCF. In the previous version I had put a call to disconnect in the destructor to ensure that the socket got cleaned up properly. Under WCF the destructor was being invoked at an inopportune time resulting in the socket being disconnected (but not actually disposed).
Various aspects to the solution, but the two main ones were:
1. Remove the 'cleanup' call to disconnect from the destructor. i.e. If you're using my service then you call the disconnect yourself.
2. Supply the decoration [OperationBehavior(TransactionScopeRequired = true)] to each method exposed by the WCF service.
I just love Koalas - they go great with Bacon.
|
|
|
|
|
sfsgfgjhklj
gjgjgkk
k
jhjhfddserty
gdfgguijkk
|
|
|
|
|
chandni patel wrote: sfsgfgjhklj
gjgjgkk
k
jhjhfddserty
gdfgguijkkRose
What kind of Testing are you doing over here?
Please DONT SPAM. If you have some problem, then asked over here, everybody will try to help you. But don't SPAM in this healthy site.
|
|
|
|
|
|
Please refrain from spamming. You have a message forum on your profile for that
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Hi there. I need some help with drawing items for a ComboBox Control.
For the most part the ComboBox draws just fine. I can scroll up and down and everything is good. The problem is when I drag the scrollbar "thumb" or box to get through the list faster. The items do not display correctly.
The ComboBox is set to DropDownList and OwnerDrawVariable.
I understand the code below is not very meaningful as I could use the windows implementation to draw the items. The program I'm working on displays certain items in bold, so the code below just illustrates the problem I have.
Thanks for your help!!
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 1 To 200
ComboBox1.Items.Add(i)
Next
End Sub
Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
If e.Index = -1 Then
Exit Sub
End If
e.DrawBackground()
e.Graphics.DrawString(ComboBox1.Items(e.Index).ToString(), e.Font, New SolidBrush(Color.Black), e.Bounds.X, e.Bounds.Y)
End Sub
End Class
|
|
|
|
|
Hi,
not sure this will fix it, however it might as your current code is too expensive: for every item drawn you:
- create a new SolidBrush
- and you don't call Dispose on it, which you should as the class offers such method.
It would be better to create a brush once, and keep it handy in a class member so you can reuse it for all items. And actually, you don't even need this as there is a class offering standard brushes, so all you need is Brushes.Black
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.
|
|
|
|
|
Thanks for the comment. You remind me to think about that more.
New code is below, but issue still exists.
I was thinking that perhaps I needed a custom class, that overrides the OnPaint method. This doesn't seem correct as the method would draw the part of the control that doesn't drop down.
I searched for quite a while and it doesn't seem anyone else has had this problem.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 1 To 200
ComboBox1.Items.Add(i)
Next
End Sub
Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
If e.Index = -1 Then
Exit Sub
End If
e.DrawBackground()
e.Graphics.DrawString(ComboBox1.Items(e.Index).ToString(), e.Font, Brushes.Black, e.Bounds.X, e.Bounds.Y)
End Sub
End Class
|
|
|
|
|
Hi,
I haven't done any ComboBox.DrawItem myself, however I use ListBopx.DrawItem a lot, and they are documented very similarly. Never had any problems. Is your CB double-buffered? is your Form? Mine normally are.
You haven't told in any detail what is wrong with the result.
here are some suggestions:
- if the comboBox.Items are strings, no need to call ToString()
- use the entire e.Bounds in DrawString, not just X and Y
- if the visual result does not provide a clue, I would add logging code to figure for which items DrawItem gets called/doesn't get called assuming some of the items are not repainted, hence show previous content.
BTW: the MSDN example on CB.DrawItem creates and doesn't dispose of its SolidBrush and Font!
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.
|
|
|
|
|
Ok. Well here is the info I have.
I changed the code quite a bit. Created a custom combobox at runtime. Form and combobox are doublebuffered.
It also creates a log file showing index, bounds, and time of DrawItem method being executed.
To describe the problem. It would appear that the Background is not being drawn correctly (but this only describes the appearance-I don't think this is the cause). When I quickly scroll the entire list, to the end, the majority of the items appear as a "blob" of black as if all of the items were drawn over top of eachother. The odd thing is this is intermittent. Out of the 20 items shown in the drop down maybe 3 or 4 will be displayed correctly.
The log file shows that when quickly dragging through a list, the items are only being drawn on either the last or second to the last visible item bounds. When dragging up the items are only drawn on either the top or second visible item bounds. Since this is the case, internally, either Windows or the .NET framework, would have to be storing the item graphics and then be moving the previous item graphics up or down.
But if you click on the scroll bar to get the next or previous "page" all the items will be redrawn from top to bottom...
I uploaded the log file to my website http://www.hoveytech.com/drawitemlog.txt
Not sure where to go from here.
Thanks for your quick answers and continued help!
Public Class Form1
Private m_fBold As Font
Private WithEvents m_cboCustom1 As CustomCombo
Private Sub m_cboCustom1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles m_cboCustom1.DrawItem
If e.Index = -1 Then
Exit Sub
End If
e.DrawBackground()
If e.Index Mod 4 = 0 Then
e.Graphics.DrawString(m_cboCustom1.Items(e.Index).ToString(), m_fBold, Brushes.Black, e.Bounds)
Else
e.Graphics.DrawString(m_cboCustom1.Items(e.Index).ToString(), e.Font, Brushes.Black, e.Bounds)
End If
LogDrawItem(e.Index, e.State, e.Bounds)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.DoubleBuffered = True
m_cboCustom1 = New CustomCombo
m_cboCustom1.Location = New Point(30, 30)
m_cboCustom1.DropDownStyle = ComboBoxStyle.DropDownList
m_cboCustom1.DrawMode = DrawMode.OwnerDrawVariable
m_cboCustom1.MaxDropDownItems = 20
Me.Controls.Add(m_cboCustom1)
m_fBold = New Font(m_cboCustom1.Font, FontStyle.Bold)
Dim i As Integer
For i = 1 To 200
m_cboCustom1.Items.Add(i)
Next
End Sub
Private Sub LogDrawItem(ByVal iIndexDrawn As Integer, ByVal iState As System.Windows.Forms.DrawItemState, ByVal rect1 As Rectangle)
Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(Application.StartupPath & "\drawitemlog.txt", True)
sw.WriteLine("DrawItem method ran for index: " & iIndexDrawn.ToString() & vbTab & "bounds: " & rect1.ToString() & vbTab & "at " & Now().ToLongDateString & " " & Now().ToLongTimeString())
sw.Close()
End Sub
End Class
Public Class CustomCombo
Inherits System.Windows.Forms.ComboBox
Public Sub New()
Me.DoubleBuffered = True
End Sub
End Class
modified on Sunday, July 19, 2009 5:58 PM
|
|
|
|
|
Hi David,
I noticed you have chosen OwnerDrawVariable, which means each item has its own height, and before DrawItem fires a MeasureItem event gets fired, asking you for the height of the item.
Suggestion:
- try OwnerDrawFixed;
- or provide a MeasureItem handler.
With this fixed it works fine for me (also remove the logging in DrawItem for good responsiveness).
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.
|
|
|
|
|
Thanks for your help!
It works now!!
|
|
|
|
|
im wanting to click on a item in a listbox and load the txt file into a richtextbox from the folder my main program resides in
can anyone show me how to do this in c#?
modified on Saturday, July 18, 2009 3:01 PM
|
|
|
|
|
What hzve you done so far? Which part of Pete's earlier and fine reply are you having trouble with?
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.
|
|
|
|
|
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedItem == (object)"New DVD")
{
TextBox1. <---- i want to load a text file here from this programs Data folder
modified on Saturday, July 18, 2009 3:19 PM
|
|
|
|
|
deadcell_6 wrote: private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
that is OK
deadcell_6 wrote: if (listBox1.SelectedItem == (object)"New DVD")
that is terrible. Why would you cast to an object?
why would you include a literal string?
I guess your ListBox is showing filenames? if so, get the filename from the selected item.
Could be as easy as
if (listBox1.SelectedIndex>=0) {
string filename=listBox1.Items[listBox1.SelectedIndex];
string s=File.ReadAllText(filename);
myTextBox.Text=s;
}
It probably could use some error handling and some refinement, but that is how it goes.
If all of this is new to you, I strongly recommend you this advice[^]. And do consider reading some CodeProject articles as well!
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.
|
|
|
|
|
thank you
now say i have 10 text files and my code is
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedItem == (object)"DVD 1")
{
TextBox1 <--- and i want to display dvd 1.txt
}
else if (listBox1.SelectedItem == (object)"DVD 2")
TextBox1 <---- and i want to display dvd 2.txt
else if (listBox1.SelectedItem == (object)"DVD 3")
TextBox1
else if (listBox1.SelectedItem == (object)"DVD 4")
TextBox1
......
sry im very new
this is what i have now and i think it would be easier to update the txt files as i get more dvds
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedItem == (object)"DVD 1")
{
TextBox1.Text = "horror" +Environment.NewLine + "actors:";
}
|
|
|
|
|
deadcell_6 wrote: private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedItem == (object)"DVD 1")
{
TextBox1 <--- and i want to display dvd 1.txt
}
else if (listBox1.SelectedItem == (object)"DVD 2")
TextBox1 <---- and i want to display dvd 2.txt
else if (listBox1.SelectedItem == (object)"DVD 3")
...
Eeek!!
Seriously, you need to learn some more of the basics of how to organise and manage data first.
How do you think an application that handles hundreds , or thousands, of pieces of information works? It certainly isn't by having a seaprate "if..." for each one.
Find out about structures, arrays, and file handling (then eventually maybe databases) and think about what information you have and how you want to organise it.
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
I develop the application using C#.net in windows xp (english version)
when I run the application the display (image) still good
but when I deploy to another computer which using windows xp (chinese version)
the display (image) become not good
does anyone knows why it happen and how to solve it?
regards,
andy
|
|
|
|
|
eyeshield21 wrote: the display (image) become not good
sure, that must be because your code is not good.
read my sig!
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.
|
|
|
|
|
|
can we make printable grid of simple dot net grid, and can we print our form objects with grid? I am trying to create my own report builder for C# forms application
|
|
|
|
|
Does this[^] article help?
/ravi
|
|
|
|
|
Hello friends,
I waana create a set for my window based apllication.I should include some com components like crystal report,ms word-2005.Can u explain me in detail.Thank u.
Cheers,
MAHESH
|
|
|
|
|