Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. Is this a safe implementation: accessing subroutine in window1 from window2

Is this a safe implementation: accessing subroutine in window1 from window2

Scheduled Pinned Locked Moved WCF and WF
designhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abiemann
    wrote on last edited by
    #1

    This implementation seems to work just great, I am however worried about the correctness of this implementation. I want to ensure that there is no possibility of a problem down the road... Window1 creates and shows Window2: Class Window1 'member variables Private myWindow2 As Window2 = Nothing Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded myWindow2 = New Window2(Me) End Sub Private Sub SomeButtonClick(....) myWindow2.ShowYourself() End Sub End Class Window2 looks like this: Partial Public Class Window2 'member variables Private m_oParent As Object Public Sub New(ByRef OParent As Object) ' This call is required by the Windows Form Designer. InitializeComponent() m_oParent = OParent End Sub Public Sub ShowYourself() 'some other stuff happens here to build the UI, once done this shows the window Me.Show() End Sub Private Sub ButtonSubmit_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButtonSubmit.Click 'refresh the UI of Window1 with the updated data that we edited in Window2 Dim OWindow1 As Window1 = DirectCast(m_oParent, Window1) OWindow1.SetStringData("Hello from Window2") OWindow1.RefreshStackPanel() 'and hide this window Me.Hide() 'ensure Window1 is immediately shown OWindow1.Focus() End Sub End Class What I'm concerned about is accessing Window1 from Window2 as can be seen in ButtonSubmit_Click() Should I have used Invoke? If so, how is that done ?

    C 1 Reply Last reply
    0
    • A abiemann

      This implementation seems to work just great, I am however worried about the correctness of this implementation. I want to ensure that there is no possibility of a problem down the road... Window1 creates and shows Window2: Class Window1 'member variables Private myWindow2 As Window2 = Nothing Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded myWindow2 = New Window2(Me) End Sub Private Sub SomeButtonClick(....) myWindow2.ShowYourself() End Sub End Class Window2 looks like this: Partial Public Class Window2 'member variables Private m_oParent As Object Public Sub New(ByRef OParent As Object) ' This call is required by the Windows Form Designer. InitializeComponent() m_oParent = OParent End Sub Public Sub ShowYourself() 'some other stuff happens here to build the UI, once done this shows the window Me.Show() End Sub Private Sub ButtonSubmit_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButtonSubmit.Click 'refresh the UI of Window1 with the updated data that we edited in Window2 Dim OWindow1 As Window1 = DirectCast(m_oParent, Window1) OWindow1.SetStringData("Hello from Window2") OWindow1.RefreshStackPanel() 'and hide this window Me.Hide() 'ensure Window1 is immediately shown OWindow1.Focus() End Sub End Class What I'm concerned about is accessing Window1 from Window2 as can be seen in ButtonSubmit_Click() Should I have used Invoke? If so, how is that done ?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This code will work, so long as it works. That is, you never check if window2 is null, or if oWindow1 is null. You should check to make sure that everything is in the state you are hoping.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups