evitar bloqueo en la ejecucion
Publicado por melqui (243 intervenciones) el 20/04/2021 20:49:00
hola chicos, necesito de una ayuda
tengo este codigo
que hace lectura de mi datagrid, problema es que cuando envio el correo agendado, la ejecucion para todo
no consigo trabajar o hacer cualquier evento. solo es liberado cuando hace la lectura de toda la grid y despues de enviar el correo.
algun ejemplo que pueda ayudar para que pueda evitar ese tipo de bloqueos?
tengo este codigo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
Private Sub EncapsularDadosEmails()
Try
Dim Cod_Item_Agendamento As Integer = 0
Dim Cod_Contatos As Integer = 0
Dim StrEmail As String = ""
Dim TotalRegistro As Integer = DgvDados.Rows.Count
Dim Cod_Agendamento As Integer = 0
Dim contReg As Integer = 1
Dim IntIntermediario As Integer = 0
lblMensagemOperacao.Text = "Iniciando, processo..."
Thread.Sleep(TimeSpan.FromSeconds(2))
If (Me.InvokeRequired = True) Then
Me.BeginInvoke(New MethodInvoker(AddressOf Me.VerificarDataDisponivelHojeAgendamentos))
Else
For i As Integer = 0 To TotalRegistro
'AQUI VEIRIFICA SE EXISTE REGISTRO NO DATAGRID MAIOR QUE QUE ZERO
If DgvDados.Rows.Count > 0 Then
'AQUI DEVE ATUALIZAR TODOS OS DADOS DO STATUS DE ENVIO.
Using DtVal_Lista As DataTable = Neg_LogicAgendamento.LeituraDatasHojeDisponivel
For Each ROWLIST As DataRow In DtVal_Lista.Rows
' Dim Status As String = ROW("STATUS_ENVIO")(0).ToString
For Each ROWGRID As DataGridViewRow In DgvDados.Rows
If ROWGRID.Cells("CODITEAGE").Value = ROWLIST.Item("CODITEAGE").ToString Then
ROWGRID.Cells("STATUS_ENVIO").Value = ROWLIST("STATUS_ENVIO").ToString
' DgvDados..Cells("STATUS_ENVIO").Value
DgvDados.Update()
Application.DoEvents()
End If
Next
Next
End Using
DgvDados.CurrentRow.Selected = False
For j = 0 To DgvDados.Rows.Count - 1 Step 1
If j <= 2 Then
Application.DoEvents()
Thread.Sleep(2)
DgvDados.Rows(j).Selected = True
End If
Next
For Each Row As DataGridViewRow In DgvDados.SelectedRows
lblMensagemOperacao.Text = Validar.StrMsg_AguardeColetandoDados & " (" & (Row.Cells("EMACLI").Value) & ") "
With ObjSmtp
.EmailOrigem = New MailAddress("melqui.serrano@outlook.com")
'aqui vai pegar email da lista
Cod_Item_Agendamento = Convert.ToInt32(Row.Cells("CODITEAGE").Value)
Cod_Contatos = Convert.ToInt32(Row.Cells("CODCLI").Value)
StrEmail = Convert.ToString(Row.Cells("EMACLI").Value)
Cod_Agendamento = Convert.ToInt32(Row.Cells("CODAGE").Value)
.List_EmailDestino.Add(New MailAddress(StrEmail))
.StrHost = "smtp.office365.com"
.IntPorta = 587
.BolSSLEnable = True
.StrUsuario = "melqui.serrano@outlook.com"
.StrSenha = "Serran035-"
End With
With ObjEmail
.StrAssunto = Row.Cells("ASSAGE").Value
.StrDescricao = Row.Cells("MENAGE").Value
If Not String.IsNullOrEmpty(Convert.ToString(Row.Cells("ANEAGE").Value.ToString)) Then
.Lst_Attachments.Add(New Attachment(Row.Cells("ANEAGE").Value))
End If
End With
'AQUI INICIA EM SEGUNDOS
lblMensagemOperacao.Text = "Verificando, Data e hora...."
' Application.DoEvents()
Thread.Sleep(TimeSpan.FromSeconds(5))
Dim TipoCalculoEnvio As Integer = 0
If DateTime.Now.ToString("yyyy-MM-dd HH:mm") > Row.Cells("DATA_HORA").Value Then
'VEIRIFIFICA SE ESTÁ VENCIDA
TipoCalculoEnvio = 1
lblMensagemOperacao.Text = " Aguarde, mensagem enviando..."
'aguarde 30 segundos se entrar como atrasado
Thread.Sleep(TimeSpan.FromSeconds(30))
Task.Run(Sub()
IntIntermediario = Logic_Email.Envio_Agendado(ObjSmtp, ObjEmail)
End Sub)
Application.DoEvents()
ElseIf DateTime.Now.ToString("yyyy-MM-dd HH:mm") = Row.Cells("DATA_HORA").Value Then
'VEIRIFIFICA SE ESTÁ VENCIDA
TipoCalculoEnvio = 0
lblMensagemOperacao.Text = " Aguarde, mensagem enviando..."
Task.Run(Sub()
IntIntermediario = Logic_Email.Envio_Agendado(ObjSmtp, ObjEmail)
End Sub)
Application.DoEvents()
Else
lblMensagemOperacao.Text = "Processando..."
Thread.Sleep(TimeSpan.FromSeconds(2))
End If
If TipoCalculoEnvio = 0 OrElse TipoCalculoEnvio = 1 Then
If IntIntermediario = 0 Then
With ObjContato
.CodigoContatos = Cod_Contatos
.StatusContatos = "Enviado"
End With
Neg_LogicContatos.UpdateStatusEmail(ObjContato)
Neg_LogicAgendamento.DeletarItemAgendamento(Cod_Item_Agendamento, Cod_Contatos)
DgvDados.Rows.Remove(Row)
lblTotalRegistro.Text = CInt(DgvDados.Rows.Count)
' DgvDados.Rows.RemoveAt(DgvDados.CurrentRow.Index)
lblMensagemOperacao.Text = "Enviado com sucesso.!"
' Application.DoEvents()
Thread.Sleep(TimeSpan.FromSeconds(2))
ElseIf IntIntermediario = 1 Then
lblMensagemOperacao.Text = "Falha ao enviar email, verifique os dados do servidor SMTP.!"
ElseIf IntIntermediario = 2 Then
lblMensagemOperacao.Text = "Falha de entrega, um ou mais anexos estão bloqueados por segurança do servidor.!"
Else
lblMensagemOperacao.Text = "Falha inesperada, tente mais tarde ou verifique os dados do servidor SMTP.!"
End If
' Application.DoEvents()
Thread.Sleep(TimeSpan.FromSeconds(3))
StrTexto.AppendLine(Now.ToLongTimeString & " " & StrEmail & " ( " & lblMensagemOperacao.Text & " )")
Dim StrOperacao As String = StrEmail & " " & lblMensagemOperacao.Text
Neg_LogicSistemas.Registrar_LogEmail(StrOperacao)
End If
Next
lblMensagemOperacao.Text = Validar.StrMsg_AguardeValidandDados
' Application.DoEvents()
Thread.Sleep(TimeSpan.FromSeconds(3))
DgvDados.ClearSelection()
Else
Exit For
End If
Next
lblMensagemOperacao.Text = Validar.StrMsg_AguardeAtualizando
'Application.DoEvents()
Thread.Sleep(TimeSpan.FromSeconds(3))
'AQUI VERIFICA O SCRIPT SE EXISTE ALGUM REGISTRO QUE NÃO ESTÁ ASOCIADO A ITENS DE AGENDAMENTOS
Neg_LogicAgendamento.VerificarExcluirAgenda()
lblMensagemOperacao.Text = ""
' txtHistorico.Text = StrTexto.ToString
'AQUI COLOCA NA ULTIMA LINHA DO HISTORICO
' txtHistorico.SelectionStart = Len(txtHistorico.Text)
' txtHistorico.ScrollToCaret()
End If
Catch ex As Exception
'MessageBox.Show(Me, String.Format("Não foi possivel prosseguir foi identificado uma falha {0} ", ex.Message), Validar.StrMsg_Titulo, MessageBoxButtons.OK, MessageBoxIcon.Error)
Dim StrErro As String = String.Format("Falha não identificada {0}", ex.Message)
Neg_LogicSistemas.Registrar_LogSistema(StrErro)
lblMensagemOperacao.Text = "Falha não identificada, reiniciando o processo..."
InttmrSeg = 0
Exit Sub
End Try
End Sub
1
2
3
Dim t_processo As New Thread(AddressOf EncapsularDadosEmails)
t_processo.IsBackground = True
t_processo.Start()
que hace lectura de mi datagrid, problema es que cuando envio el correo agendado, la ejecucion para todo
no consigo trabajar o hacer cualquier evento. solo es liberado cuando hace la lectura de toda la grid y despues de enviar el correo.
algun ejemplo que pueda ayudar para que pueda evitar ese tipo de bloqueos?
Valora esta pregunta


0