I'm having a slow system that I created in C # using Entity Framework. At the moment I am going to save a record from an attachment, I am compressing the file. Before I check if it is .jpg or .pdf (only extensions accepted by the system). The files I am attaching have a maximum of 1MB, and yet the system is slow ... Appears as "Not responding" and after a certain time (approximately 20 seconds), persists. Does anyone know what it can be?
I already checked the network (it is normal) and the configuration of the computer is good.
Here are my method codes for saving and compressing files.
private void btnSalvar_Click(object sender, EventArgs e)
{
if (ValidaForm())
{
FANEXOMOVIMENTACAO anex = new FANEXOMOVIMENTACAO
{
MovimentacaoID = movimentacao.MovimentacaoID,
AnexoID = txtCodAnexo.Text,
Descricao = txtDescricao.Text,
Tipo = "COMUM",
Nome = Path.GetFileNameWithoutExtension(txtArquivo.Text),
Extensao = Path.GetExtension(txtArquivo.Text),
Arquivo = (Path.GetExtension(txtArquivo.Text) == ".pdf" ? Global.EncriptPDF(txtArquivo.Text) : Global.EncriptFoto(txtArquivo.Text)),
DataCadastro = DateTime.Now,
UsuarioCadastro = FormPrincipal.getUsuarioAcesso().LoginUsr
};
using (controle = new ControleFAnexoMovimentacao())
{
controle.Create(anex);
controle.SaveAll();
Global.MsgSucesso("Registro salvo com sucesso.");
salvo = true;
}
if (Global.NovoRegistro() == DialogResult.Yes)
LimparCampos();
else
this.Close();
}
}
And this is to compress the files:
public static byte[] EncriptFoto(string img)
{
byte[] bytesImagem = null;
FileStream fstream = new FileStream(img, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
bytesImagem = br.ReadBytes((int)fstream.Length);
return CompressBytes(bytesImagem);
}
public static byte[] EncriptPDF(string pdf)
{
byte[] arrayDeBytes;
using (Stream stream = new FileStream(pdf, FileMode.Open))
{
arrayDeBytes = new byte[stream.Length + 1];
stream.Read(arrayDeBytes, 0, arrayDeBytes.Length);
}
return CompressBytes(arrayDeBytes);
}