Arduino Compiles First time , but wont compile/upload after that.

Hi everyone, I'm new here, so excuse me if I make any post mistakes

The problem I am facing is strange, I recently bought an Arduino Mega (Atmega2560) and when I try to upload the most simple code just to test it, it doesn't work properly. I tried disabling antivirus, firewall and looked at dozen forum posts about libraries. I am still stuck

This is the simple code I tried to upload for the first time

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(13,HIGH);
  delay(300);
  digitalWrite(13,LOW);
  delay(1000);
  digitalWrite(13,HIGH);
  delay(50);
  digitalWrite(13,LOW);
  delay(1000);
}

After I press Compile / Upload

it does it well the first time and I get this log:

Bla Bla 9000 char max for forum post 
ETC...
ETC...

"C:\\Users\\NeXuS\\AppData\\Local\\Temp\\arduino_build_909004\\core\\new.cpp.o"
Archiving built core (caching) in: C:\Users\NeXuS\AppData\Local\Temp\arduino_cache_303078\core\core_arduino_avr_mega_cpu_atmega2560_0c812875ac70eb4a9b385d8fb077f54c.a
Linking everything together...
BLA BLA 9000 Char Max for Forum
Sketch uses 1542 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 8183 bytes for local variables. Maximum is 8192 bytes.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM7 -b115200 -D -Uflash:w:C:\Users\NeXuS\AppData\Local\Temp\arduino_build_909004/sketch_may25a.ino.hex:i 

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM7
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops            a         : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Wiring
         Description     : Wiring
         Programmer Model: AVRISP
         Hardware Version: 15
         Firmware Version Master : 2.10
         Vtarget         : 0.0 V
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: reading input file "C:\Users\NeXuS\AppData\Local\Temp\arduino_build_909004/sketch_may25a.ino.hex"
avrdude: writing flash (1542 bytes):

Writing | ################################################## | 100% 0.29s

avrdude: 1542 bytes of flash written
avrdude: verifying flash memory against C:\Users\NeXuS\AppData\Local\Temp\arduino_build_909004/sketch_may25a.ino.hex:
avrdude: load data flash data from input file C:\Users\NeXuS\AppData\Local\Temp\arduino_build_909004/sketch_may25a.ino.hex:
avrdude: input file C:\Users\NeXuS\AppData\Local\Temp\arduino_build_909004/sketch_may25a.ino.hex contains 1542 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.23s

avrdude: verifying ...
avrdude: 1542 bytes of flash verified

avrdude done.  Thank you.

but if I make a small modification to the code, or even if i don't touch the code and try to Compile/Upload again, it wont.

It just shows me this:

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\NeXuS\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -vid-pid=0X2341_0X0042 -ide-version=10812 -build-path C:\Users\NeXuS\AppData\Local\Temp\arduino_build_909004 -warnings=all -build-cache C:\Users\NeXuS\AppData\Local\Temp\arduino_cache_303078 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\NeXuS\Desktop\sketch_may25a\sketch_may25a.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\NeXuS\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -vid-pid=0X2341_0X0042 -ide-version=10812 -build-path C:\Users\NeXuS\AppData\Local\Temp\arduino_build_909004 -warnings=all -build-cache C:\Users\NeXuS\AppData\Local\Temp\arduino_cache_303078 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\NeXuS\Desktop\sketch_may25a\sketch_may25a.ino
Using board 'mega' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
Error compiling for board Arduino Mega or Mega 2560.

I chose
Tools > Board > Arduino Mega or Mega 2560
Processor > ATmega2560 (Mega 2560)
Port> COM7 (Arduino Mega or Mega 2560)

Get board info shows :
BN: Arduino Mega or Mega 2560
VID: 0x2341
PID: 0x0042
SN: 55838343034351E05112

What is noticed was weird. when i change the Processor to ATmega1280 and then back to ATmega2560
it does compile and upload but again ,just once, and then the same thing again.
It's really frustrating.

Thank You for your time!

I suspect an issue with the compilation cache (which is cleared when you switch board selections. Try this:

File > Preferences

Click the link at the line following More preferences can be edited directly in the file.

Open the file preferences.txt you find in the folder that opens in your file browser software using a text editor.

Close the Arduino IDE (if you don't do this, the changes you make to preferences.txt are reverted).

Add the following line anywhere in the file:

compiler.cache_core=false

Save the file.

Start the Arduino IDE.

Try compiling twice. Does the issue still occur?