Click here to Skip to main content
15,898,371 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Privilege escalation in VB6 and VB.net programatically Pin
kilkfoe119-Mar-10 7:17
kilkfoe119-Mar-10 7:17 
QuestionAdding a new row to DataSource [modified] Pin
Floodlight17-Mar-10 14:05
Floodlight17-Mar-10 14:05 
AnswerRe: Adding a new row to DataSource Pin
Anubhava Dimri17-Mar-10 18:42
Anubhava Dimri17-Mar-10 18:42 
GeneralRe: Adding a new row to DataSource Pin
Floodlight17-Mar-10 19:06
Floodlight17-Mar-10 19:06 
GeneralRe: Adding a new row to DataSource Pin
Anubhava Dimri17-Mar-10 19:38
Anubhava Dimri17-Mar-10 19:38 
AnswerRe: Adding a new row to DataSource Pin
Dave Kreskowiak18-Mar-10 3:49
mveDave Kreskowiak18-Mar-10 3:49 
GeneralRe: Adding a new row to DataSource Pin
Floodlight18-Mar-10 12:40
Floodlight18-Mar-10 12:40 
QuestionMultiThreading in TabPages! Pin
dotnetme217-Mar-10 9:16
dotnetme217-Mar-10 9:16 
I have an application that has a tab control and on each tab there is a button that runs a process, I have set up the process to run on a separate thread which kind of works. I can rig it to work the way I want for testing but not the way it should work. Basically I want to Click the button to run the process and then be able to navigate to another tab do other work and when the process finishes to update the tab from which it was called while I'm on a different tab. This works if I hard code the tabindex in the SetText sub. I should mention the tabs are created dynamically on demand by the user at run time from a template class. I will list the code segments below and will show the rigged working code as well below my issues. Here are my issues.

1. Application Crashes(encountered a problem and has to close) when I attempted either of statement Only when the new thread calls the procedure that contains this code.
a) If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then

b) EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text


2. I need to capture the tab index that started the new thread because when the thread returns the info and I need to update the textbox from "SetText" on the tab from which the thread was called. Since the tabs are Dynamically created from a template they all have textboxes with the same name in this case "txtMaxAddr".
TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [text]


3. Can I run a separate thread on each tab? i.e. on a tab click the button to run the process switch another tab click the button run the process for that tab... etc...
--------
Public Class CreateTab
  Public Function ReadTab(ByRef tpRead As TabPage, ByVal dgCurrentRow As DataGridViewRow)
.
.dynamicaaly created code is here
.
        'btnMax
        '
        btnMax.Location = New System.Drawing.Point(285, 6)
        btnMax.Name = "btnMax"
        btnMax.Size = New System.Drawing.Size(109, 23)
        btnMax.TabIndex = 15
        btnMax.Text = "Match to Account"
        btnMax.UseVisualStyleBackColor = True
        AddHandler btnMax.Click, AddressOf Form1.btnMax_Click
.
.
.
  End function
End Class

Private demoThread As Thread = Nothing
Delegate Sub SetTextCallback(ByVal [text] As String)
-
Private Sub dgInbox_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgInbox.CellDoubleClick

        Dim iTabCount, iIndex As Integer

        If TabControl1.TabPages.ContainsKey(dgInbox.CurrentRow.Cells(0).Value.ToString()) = False Then
            TabControl1.TabPages.Add(dgInbox.CurrentRow.Cells(0).Value.ToString(), Mid(dgInbox.CurrentRow.Cells(2).Value.ToString(), 1, 25))
            Me.tpRead.SuspendLayout() 
 
            CreateTab.ReadTab(TabControl1.TabPages.Item(TabControl1.TabPages.Count - 1), dgInbox.CurrentRow)

            Me.tpRead.ResumeLayout(False)             Me.tpRead.PerformLayout() 
            
            TabControl1.SelectTab(TabControl1.TabPages.Count - 1) 'set to currently displayed tab

        Else
            iIndex = TabControl1.TabPages.IndexOfKey(dgInbox.CurrentRow.Cells(0).Value.ToString())
            TabControl1.SelectTab(iIndex) ' tab already was created diplay it
        End If

    End Sub
-
Public Sub btnMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMax.Click
     
        'EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text

        ' Create a thread and start it.
        Me.demoThread = New Thread(New ThreadStart(AddressOf Me.CallMax))
        Me.demoThread.Start()
End Sub
-
Public Sub CallMax()
      
        Dim AccountInfo As String
     '1. Issue #1b 
        EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
        MaxConn.LinkToAccount(EmailAddr, AccountInfo)
     
        Dim NewText As String = AccountInfo
       
        'If TabControl1.SelectedTab.Controls("txtaddr").InvokeRequired Then
    '1. Issue #1a    
        If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then
            'It's on a different thread, so use Invoke.
            Dim d As New SetTextCallback(AddressOf SetText)
            Me.Invoke(d, New Object() {[NewText]})
        Else
            ' It's on the same thread, no need for Invoke.
            TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [NewText] 
        End If

        '=====
End Sub
-
    Private Sub SetText(ByVal [text] As String)
   '2. Issue number 2
        TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [text]
    End Sub

--Rigged to work---
Public Sub CallMax()
      
        Dim AccountInfo As String
       
        'EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
        MaxConn.LinkToAccount(EmailAddr, AccountInfo)
     
        Dim NewText As String = AccountInfo
       
        'If TabControl1.SelectedTab.Controls("txtaddr").InvokeRequired Then
    '1. Issue #1    
        'If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then
            'It's on a different thread, so use Invoke.
            Dim d As New SetTextCallback(AddressOf SetText)
            Me.Invoke(d, New Object() {[NewText]})
        'Else
            ' It's on the same thread, no need for Invoke.
            'TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [NewText] 
        End If

        '=====
End Sub
-
    Private Sub SetText(ByVal [text] As String)
   '2. Issue number 2
        'TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [text]
        TabControl1.TabPages(3).Controls("txtMaxAddr").Text = [text]

    End Sub
Thanks in advance for any help!

dotnetme2

Answerpartial answer Pin
Luc Pattyn17-Mar-10 9:51
sitebuilderLuc Pattyn17-Mar-10 9:51 
GeneralRe: partial answer Pin
dotnetme217-Mar-10 10:30
dotnetme217-Mar-10 10:30 
QuestionUser Control Array [modified] ---- Solved Pin
Ibsy17-Mar-10 4:26
professionalIbsy17-Mar-10 4:26 
AnswerRe: User Control Array Pin
Dave Kreskowiak17-Mar-10 4:57
mveDave Kreskowiak17-Mar-10 4:57 
GeneralRe: User Control Array Pin
Ibsy17-Mar-10 13:47
professionalIbsy17-Mar-10 13:47 
GeneralRe: User Control Array Pin
Dave Kreskowiak17-Mar-10 14:39
mveDave Kreskowiak17-Mar-10 14:39 
Questiondecimal value in .sdf database Pin
ejaz_pk17-Mar-10 4:12
ejaz_pk17-Mar-10 4:12 
AnswerRe: decimal value in .sdf database Pin
Luc Pattyn17-Mar-10 4:18
sitebuilderLuc Pattyn17-Mar-10 4:18 
AnswerRe: decimal value in .sdf database Pin
Dave Kreskowiak17-Mar-10 4:23
mveDave Kreskowiak17-Mar-10 4:23 
AnswerRe: decimal value in .sdf database Pin
Dalek Dave17-Mar-10 4:25
professionalDalek Dave17-Mar-10 4:25 
AnswerRe: decimal value in .sdf database Pin
εїзεїзεїз17-Mar-10 6:25
εїзεїзεїз17-Mar-10 6:25 
GeneralRe: decimal value in .sdf database Pin
ejaz_pk18-Mar-10 19:40
ejaz_pk18-Mar-10 19:40 
Questiondelimitted files Pin
Daniel Engelkes16-Mar-10 17:46
Daniel Engelkes16-Mar-10 17:46 
AnswerRe: delimitted files Pin
_Damian S_16-Mar-10 18:00
professional_Damian S_16-Mar-10 18:00 
AnswerRe: delimitted files Pin
Andy_L_J16-Mar-10 19:04
Andy_L_J16-Mar-10 19:04 
GeneralRe: delimitted files Pin
Daniel Engelkes18-Mar-10 3:39
Daniel Engelkes18-Mar-10 3:39 
GeneralRe: delimitted files Pin
Andy_L_J18-Mar-10 8:45
Andy_L_J18-Mar-10 8:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.